-
Error #2025:
Hi I'm getting this error:ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
in my code and don't know what to do about it. I read that it happens because i'm trying to call removeChild from a null variable but it is not null, so I'm confused about why it's happening and what to do, here's my code:
public function destroyShip(EnemyShip:Object):void
{
for (var i:int = _gameModel.enemy1Ships.length-1; i >= 0;i--) {
if (_gameModel.enemy1Ships[i].image == EnemyShip.image)
{
_gameModel.screen.removeChild(_gameModel.enemy1Shi ps[i].image);
_gameModel.enemy1Ships.splice(EnemyShip,1);
TileExplosion(100,100,1,1);
}
}
}
if anyone can help me please do. the Parameter "EnemyShip" is filled with the enemy ship sprite.
-
Well, the most obvious answer would be that _gameModel.screen isn't the direct parent of the enemy ship. If it is being added to some sub child of _gameModel.screen it has to be removed from that same sprite/movieclip. You can check by tracing the ship's parent if you're not sure. You can also just do enemy1Ships[i].parent.removeChild(enemy1Ships[i]) but I'd recommend figuring out what its parent is first so you understand what is going on better
-
I tried what you said with:
_gameModel.enemy1Ships[i].image.parent.removeChild(_gameModel.enemy1Ships[i].image)
and it seems to be working now. The parent traces as the class I am using, Enemy1. I can't really figure what is going on though because I added the ship as'
_gameModel.screen.addChild(enemy1Ship.image);
_gameModel.enemy1Ships.push(enemy1Ship);
go figure. Shouldn't it be _gameModel.screen.removeChild(etc....)?
thanks for the advice
Last edited by WEich1213; 10-02-2011 at 11:38 PM.
-
Sorry, I thought it was working but now it's giving me this error in the line that I am trying to remove the ship in:
Error #1009: Cannot access a property or method of a null object reference.
for this code:
_gameModel.enemy1Ships[i].image.parent.removeChild(_gameModel.enemy1Ships[i].image);
if you can tell me why please do thanks for all the help!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|