繁体   English   中英

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

[英]Flash as3: Load external swf to main stage from button inside a movie clip

我的主要舞台上有一个电影剪辑。 有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);
}

将已加载的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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM