javascript - For in loop not working with global namespace variable -


i'm working on canvas animation/game , having problems in loop in 1 of functions. in interest space removed code.

function loadscene(){ // function issue                 console.dir(game.frames); //195 objects 0{}, 1{}, 2{}, etc.                 (var prop in game.frames){                     console.log(prop); //does not here                     if (game.frames[prop].scene == game.currentscene){                         game.scenedata.push(game.frames[prop]);                     }                 }             }  function loadframes(){                 //xhr request                 // if successs load json data namespace variable                 // canvas                 // drawimage loading screen                 // return true  }   function startgame(){    if(loadframes()){        loadscene();    } } 

the in loop fails every time (never goes loop) though there items in in object. thought might have been hoisting issue put variables namespace @ top of script , rearranged functions. think async issue since function works when use debugger step through function, if case have no idea how fix it.

function loadframes(){             //xhr request             // if successs load json data namespace variable             // canvas             // drawimage loading screen             // return true } 

the xmlhttprequest within loadframes may work asynchronously, whereas loadframes works synchronously. loadframes returns true after sending ajax request, regardless of if frames(maybe mean game.frames?) have been loaded; i.e. it not check response of request.


Comments