Javascript array assinging to variable gets undefined -


hello trying draw few images .so @ first made group(i think function part of plugin using thats no matter) made array store name , src of several images , calling loop draw images thing got no results @ no errors nothing try alert "b.name" , "b.src" result got undefined explain me problem cuz me seems

            var mapgroup = new group();             var mapvillage = [                 {name: "leaf", src: "js/leaf.png"},                 {name: "sand", src: "js/sand.png"},                 {name: "stone", src: "js/stone.png"},                 {name: "cloud", src: "js/cloud.png"},                 {name: "mist", src: "js/mist.png"},                 {name: "rain", src: "js/rain.png"},                 {name: "grass", src: "js/grass.png"},                 {name: "sound", src: "js/sound.png"},                 {name: "hotwater", src: "js/hotwater.png"},                 {name: "waterfall", src: "js/waterfall.png"}             ];              for(var = 0; < mapvillage.length; i++){                 var b = mapvillage[i];                 b = new sprite(game.width, game.height);                 b.image = game.assets[b.src];                 alert(b.name);                 mapgroup.addchild(b);             } 

your mistake here

   var b = mapvillage[i];    b = new sprite(game.width, game.height); 

you assigning b first entry of mapvillage, have b.image looking for. overriding in next line. when calling b.image next, looking 'image' on "sprite", not have property ;-)

to solve it, assign sprite new variable. var sprite = new sprite(game.width, game.height);


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -