I’m making a navigation bar which contains 4 buttons, each button will load external swf file when clicked.
I want that every time one swf file is added to stage, it’ll replace the previous one.
Therefore I created a variable j in order to prevent any stack of the swf files.
It doesn’t work as only the first swf file was able to be added to and removed from stage.
Any suggestion??
var j:int = 0;
var _SWFLoader:SWFLoader;
var swfCont:Sprite = new Sprite();
addChild(swfCont);
button1.name = "button1";
button2.name = "button2";
button3.name = "button3";
button4.name = "button4";
button1.addEventListener(MouseEvent.CLICK, gotClicked);
button2.addEventListener(MouseEvent.CLICK, gotClicked);
button3.addEventListener(MouseEvent.CLICK, gotClicked);
button4.addEventListener(MouseEvent.CLICK, gotClicked);
function gotCLicked(e:MouseEvent):void
{
j += 1;
if (j == 1)
{
if (e.target.name == "button1")
{
_SWFLoader = new SWFLoader("AAA.swf");
_SWFLoader.load();
swfCont.addChild(_SWFLoader.content);
}
if (e.target.name == "button2")
{
_SWFLoader = new SWFLoader("BBB.swf");
_SWFLoader.load();
swfCont.addChild(_SWFLoader.content);
}
if (e.target.name == "button3")
{
_SWFLoader = new SWFLoader("CCC.swf");
_SWFLoader.load();
swfCont.addChild(_SWFLoader.content);
}
if (e.target.name == "button4")
{
_SWFLoader = new SWFLoader("DDD.swf");
_SWFLoader.load();
swfCont.addChild(_SWFLoader.content);
}
}
else if (j > 1)
{
swfCont.removeChild(_SWFLoader.content);
j = 1;
}
}