mercredi 24 mai 2017

Check If Child not exist - Addchild (AS3)

Hello I wanna ask about if else statement to check if the child is already exist then it wont be added on the stage, but if the child isn't on the stage then it will be added on the stage.

I have two frame, In the first frame you can click a button to go to the next frame, what I want is the first frame will import "menu1" to the stage just once, and if we go to the next frame and go back to the first frame, and the "menu1" is already on stage, it wont import "menu1" again.

My problem is, when I go back from frame 2 to frame 1, it keeps adding "menu1" to the stage.Can you guys fix my problem by explaining to me .

I'll let you guys figured out the problem with my coding. Thankyou very much.

stop();

import flash.display.Loader;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.display.Stage;

var menu1:Loader = new Loader();
var request1:URLRequest = new URLRequest ("MENU1.swf");
menu1.load(request1);

if (stage.contains(menu1)){

}
else 
{
addChild(menu1);
}

Aucun commentaire:

Enregistrer un commentaire