0
votes

I have a movie clip on my main stage. There are 2 buttons. I need the 2 buttons to load an external swf, place it on the main stage and have it centered there.

I can get the script to load them in the current movie clip but I need them to be placed on the main stage.

var loader_mc:Loader = new  Loader();
addChild(loader_mc);

buttoninsidemc1.addEventListener(MouseEvent.CLICK,  buttonClick)

function buttonClick(e:MouseEvent):void
{
    try {
        loader_mc.unloadAndStop();
    } catch(e:Error) {

    }

    var urlRequest : URLRequest = new  URLRequest("externalswf1.swf");
    loader_mc.load(urlRequest);
}


buttoninsidemc2.addEventListener(MouseEvent.CLICK,  buttonClick2)

function  buttonClick2(e:MouseEvent):void
{
    try {
        loader_mc.unloadAndStop();
    } catch(e:Error) {

    }

    var urlRequest : URLRequest = new  URLRequest("externalswf2.swf");
    loader_mc.load(urlRequest);
}
1

1 Answers

1
votes

Code that will add loaded swf to the stage:

function buttonClick2(e:MouseEvent):void {
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    loader.load(new URLRequest("externalswf2.swf"));
}

function onComplete(e:Event):void {
    var movie:* = LoaderInfo(e.currentTarget).content;
    //Adding content to the stage
    stage.addChild(movie);
}

Or you can change only one line of code in your realisation:

   stage.addChild(loader_mc);