actionscript 3 - for each loop in adobe flash -
c:\users\ifcdu1\desktop\mtwater\src\fish.as:87: 1067: implicit coercion of value of type string unrelated type food.
can tell me why getting error? trying access x,y values of object of type food in array holds food objects
public function loop(e:event):void { if(foodinpond > 0) { var foodarray:array = fooddroppedarray; (var i:food in fooddroppedarray); { if (getdistance(this.x - fooddroppedarray[i].x , this.y - fooddroppedarray[i].y) < 100) { if(!i.eaten) { movetofood(newfood); } else if (i.eaten) { updateposition(); } } else { updateposition(); } } } else { updateposition(); } }
for each(var i:food in fooddroppedarray) { if(getdistance(this.x - i.x , this.y - i.y) < 100) { if(!i.eaten) movetofood(newfood); else if(i.eaten) updateposition(); else updateposition(); } } you forgot add each keyword after for. also, had:
if(getdistance(this.x - fooddroppedarray[i].x , this.y - fooddroppedarray[i].y) < 100) fooddroppedarray[i] have been invalid (null) here, need use i did in latter parts of loop.
Comments
Post a Comment