arrays - JavaScript: Why do I keep getting this error with a literal object custom method? -


ctx predefined along other canvas properties. didn't want bombard page huge chunk of code.

i'm building array of literal objects , have 1 method. when try call method says it's undefined, this:

var enemiesarray = [];  function createenemy(ene) {     (e = 0; e <= ene; e++) {         var t = math.floor(math.random() * 291)         var p = math.floor(math.random() * 101)         var enemies = {             x: t,             y: p,             hp: 20,             dir: 0,             damageimage: function () {                 return "bomber4.png";             }         }         enemiesarray.push(enemies);     } } //an interval set call following function: function drawenemey() {     (zdp in enemiesarray) {         img = new image();         img.src = "images/" + enemiesarray[zdp].damageimage(); //this    error.         img.style.width = "20px";         ctx.drawimage(img, enemiesarray[zdp].x, enemiesarray[zdp].y);         //move side side         if (enemiesarray[zdp].dir == 0) {             //move left             enemiesarray[zdp].x -= 1;             if (enemiesarray[zdp].x <= 0) enemiesarray[zdp].dir = 1;         } else {             //move right             enemiesarray[zdp].x += 1;             if (enemiesarray[zdp].x >= 290) enemiesarray[zdp].dir = 0;         }         //check if hit     } } 

what don't understand when run code is,enemiesarray[zdp].x through enemiesarray[zdp].dir defined, enemiesarray[zdp].damageimage() isn't.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -