I'm working on a simple Flash game for school. In one level, multiple enemies spawn and the player is supposed to shoot them. I used removeChild() to get rid of the enemy that got shot, but when I click (hit) an enemy, everything on my stage gets removed; it goes completely blank.
The function to populate my stage with enemies is the following:
private function Game2():void{
for (var i:uint=0; i<50; i++) {
var man:MovieClip = new man_mc();
man.x=Math.random()*750;
man.y=Math.floor(Math.random()*(70))+350;
addChild(man);
man.addEventListener(MouseEvent.CLICK, getroffen);
}
function 'getroffen' checks if an enemy got hit:
public function getroffen(evt:MouseEvent):void{
trace("hit");
this.parent.removeChild(this);
}
Kind of confused here as to why it removes everything on the stage instead of removing just the enemy I click on. Any help? Thanks alot.