[英]Load External SWF through ComboBox AS3
I am trying to create a ComboBox that loads and unloads an external SWF onto stage using ActionScript 3.0 using Flash CS5. 我正在尝试创建一个ComboBox,该组件将使用Flash CS5的ActionScript 3.0将外部SWF加载和卸载到舞台上。
Currently there are 2 list items in the combo box: Home and About. 当前,组合框中有2个列表项:“主页”和“关于”。 Upon selecting Home or About option from ComboBox it displays both Home and About SWF at once when selected. 从ComboBox中选择“主页”或“关于”选项后,选中后将同时显示“主页”和“关于SWF”。
I only want 1 SWF to be displayed only when selected, not all. 我只希望仅在选中时显示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;
}
}
You may have to do addChild after the swf file has completed loading. 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");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.