Reputation: 319
When I remove a page and add another page, it shows this error. Why does it do that? It says the error is located at the line "parent.removeChild(homePage);
function onPlayButtonsClick(event:MouseEvent):void
{
//var level1Page = new Level1Page;
parent.addChild(level1Page);
parent.removeChild(homePage);
}
private function onKeyDown(event: KeyboardEvent): void
{
if (event.keyCode == Keyboard.A)
{
vx = -5;
side = true;
}
else if (event.keyCode == Keyboard.D)
{
vx = 5;
side = true;
}
else if (event.keyCode == Keyboard.W)
{
vy = -5;
up = true;
}
else if (event.keyCode == Keyboard.S)
{
vy = 5;
up = true;
}
}
private function onKeyUp(event: KeyboardEvent): void
{
if (event.keyCode == Keyboard.A || event.keyCode == Keyboard.D)
{
vx = 0;
side = false;
}
else if (event.keyCode == Keyboard.S || event.keyCode == Keyboard.W)
{
vy = 0;
up = false;
}
}
This is the code for my level1Page keyboard event.
Upvotes: 0
Views: 79
Reputation: 9839
You got the #2025
error because your homePage
object is not a child of the mentioned parent
, to avoid such problem, try always to do like this :
yourObject.parent.removeChild(yourObject);
In your case it will be :
homePage.parent.removeChild(homePage);
You can take a look on my answer of this question : Remove Child and AS3 2025 Error.
Hope that can help.
Upvotes: 0