Flash as3:从影片剪辑内的按钮将外部swf加载到主舞台

时间:2014-03-11 20:45:35

标签: actionscript-3 flash

我的主舞台上有一个电影剪辑。有2个按钮。我需要2个按钮来加载外部swf,将它放在主舞台上并让它居中。

我可以让脚本在当前的影片剪辑中加载它们,但我需要将它们放在主舞台上。

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 个答案:

答案 0 :(得分:1)

将加载的swf添加到舞台的代码:

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);
}

或者您只能在实现中更改一行代码:

   stage.addChild(loader_mc);