Question

I'm an as3 newbie, i'm loading external swf files by clicking different buttons but using only one function which works fine.

//main
mainCloseBtn.visible = false;
movieloaderbg.visible = false;
M1L1Btn1.visible = false;

//Load activities
var Xpos:Number = 0;
var Ypos:Number = 0;
var swf:MovieClip;
var loader:Loader = new Loader();
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);
// Btns Universal function
function btnClick(event:MouseEvent):void {
    removeChild(loader);
    var newSWFRequest:URLRequest = new URLRequest("activities/" + event.target.name + ".swf");
    loader.load(newSWFRequest);
    loader.x = Xpos;
    loader.y = Ypos;
    addChildAt(loader,3);
    mainCloseBtn.visible = true;
}
// Btn listeners
wrong.addEventListener(MouseEvent.CLICK, btnClick);
// Back btn
backBtn.addEventListener(MouseEvent.CLICK, backBtnClick);
function backBtnClick(evt:MouseEvent):void {
    gotoAndStop("M1Lessons");
}
// Video Button
videoBtn.addEventListener(MouseEvent.CLICK, videoBtnClick);
function videoBtnClick(evt:MouseEvent):void {
    mainCloseBtn.visible = true;
    M1L1Btn1.visible = true;
    M1L1Btn1.gotoAndPlay(2);
}
//Main Close Button
mainCloseBtn.addEventListener(MouseEvent.CLICK, mainCloseBtnClick);
function mainCloseBtnClick(evt:MouseEvent):void {
    mainCloseBtn.visible = false;
    loader.unload();
    M1L1Btn1.visible = false;
    M1L1Btn1.stop();
}

I'm trying to unload the swfs by clicking on the close button, but the problem is when the swf is loaded i can no longer see the close btn, I've tried to use swap depth but isn't working.

I would really appreciate it if someone could help me!

Thanks

Was it helpful?

Solution

try this:

replace

addChild(loader);

with

addChildAt(loader,0);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top