I'm trying to build game like chicken invaders and i get this eror :
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller. at flash.display::DisplayObjectContainer/removeChild() at superstudent7_fla::MainTimeline/moveBullet()
this problem occurs when my space ship shoots.
to solve this , i need to know 2 things:
my bullets are defined as
MovieClip
s ,and they are not on stage.. so i brought them to the stage like this:function shooting(e:Event):void { var Bullet:bullets = new bullets(); // bullets is class name of my movieClip ... ... ... addChild(Bullet); Bullet.addEventListener(Event.ENTER_FRAME,moveBullet); }//End of shooting
i need to know if its ok add the bullet to the stage like this? or there is another way?
here is the code that makes the 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 is the problem ... .... .... }//End if }//End for ...... ..... }//End of moveBullet
enemy- is the container of all The Enemies (movieClips)