flash - Error #2025 AS3 -
i'm trying build game chicken invaders , eror :
argumenterror: error #2025: supplied displayobject must child of caller. @ flash.display::displayobjectcontainer/removechild() @ superstudent7_fla::maintimeline/movebullet()
this problem occurs when space ship shoots.
to solve , need know 2 things:
my bullets defined
movieclip
s ,and not on stage.. brought them stage this:function shooting(e:event):void { var bullet:bullets = new bullets(); // bullets class name of movieclip ... ... ... addchild(bullet); bullet.addeventlistener(event.enter_frame,movebullet); }//end of shooting
i need know if ok add bullet stage this? or there way?
here code makes bullet move:
function movebullet(e:event):void { e.target.y -=10; for(var i=0;i<enemy.numchildren;i++) { if(e.target.hittestobject(enemy.getchildat(i))) { counthits[i]=counthits[i]+1; e.target.removeeventlistener(event.enter_frame,movebullet); removechild(movieclip(e.target)); //here problem ... .... .... }//end if }//end ...... ..... }//end of movebullet
enemy- container of enemies (movieclips)
it seems class has movebullet
function not same container of enemies, you're removing movieclip not child of container, error message explains. this:
if(movieclip(e.target).parent) { movieclip(e.target).parent.removechild(movieclip(e.target)); }
that removes target of event whatever parent added to. , doesn't remove if it's not added display list anywhere, don't other errors.
alternatively, since state enemy
container, this:
enemy.removechild(movieclip(e.target));
Comments
Post a Comment