通过ComboBox AS3加载外部SWF

时间:2013-02-01 03:01:28

标签: actionscript-3 flash actionscript combobox

我正在尝试创建一个ComboBox,使用Flash CS5使用ActionScript 3.0将外部SWF加载到舞台上。

目前,组合框中有2个列表项:Home和About。 从ComboBox中选择Home或About选项后,它会在选中时同时显示Home和About SWF。

我只想在选择时显示1个SWF,而不是全部。

menuList.addItem({label:"Choose"});
menuList.addItem({label:"Home",path:"home_load.swf"});
menuList.addItem({label:"About",path:"about.swf"});

menuList.addEventListener(Event.CHANGE, Home);
menuList.addEventListener(Event.CHANGE, About);

var loader:Loader = new Loader();
loader.unloadAndStop();


function Home(e:Event):void
{
    if (e.currentTarget.selectedItem.path)
    {
        var loader:Loader = new Loader();
        //loader.unloadAndStop();
        loader.load(new URLRequest("home_load.swf"));

        addChild(loader);
        //loader.unloadAndStop();
        loader.x = 0;
        loader.y = 190;
    }
}

function About(e:Event):void
{
    if (e.currentTarget.selectedItem.path)
    {
        //loader.unloadAndStop();
        var loader:Loader = new Loader();
        loader.load(new URLRequest("about.swf"));

        addChild(loader);
        //loader.unloadAndStop();
        loader.x = 0;
        loader.y = 190;
    }
}

1 个答案:

答案 0 :(得分:0)

在swf文件加载完成后,您可能必须执行addChild。

//These listeners detect when the file has finished loading, and if the
//correct file is loaded.
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
swfLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);

//The load method then loads the SWF file into the loader object.
swfLoader.load(my_url);

//This function adds the external SWF to the stage.
function finishLoading(loadEvent:Event) {
addChild(loadEvent.currentTarget.content);
}

//This function displays a message if the file is not found.
function errorHandler(errorEvent:Event):void {
trace("file missing");
}