ive made a button in the scene 1 which i have managed to navigate to scene 2 but when i click the button it goes to scene 2 but displays everthing that is in scene 1 in scene 2, how can sort this out so upon the button click in scene 1 it goes to scene 2 and only display content in scene2.
this is the code im using to navigate from scene1 to 2:
button1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene);
function fl_ClickToGoToScene(event:MouseEvent):void
{
MovieClip(this.root).gotoAndPlay(10, "Scene 2");
}
All stage instances created by calling addChild()
from ActionScript have to be removed by calling removeChild()
. Only those instances you place on the stage from the library in the IDE will automatically be removed when you switch scenes.
Try this:
function fl_ClickToGoToScene(event:MouseEvent):void
{
for ( var i:int = root.numChildren-1; i >= 0; i--) {
root.removeChildAt(i);
}
root.gotoAndPlay(10, "Scene 2");
}