简体   繁体   English

单击按钮,AS3加载外部SWF

[英]AS3 loading external swf on button click

In AS3 (Flash), I want an external swf-file to load when I click a specific menu button. 在AS3(Flash)中,我希望在单击特定菜单按钮时加载外部swf文件。 I also want the swf to disappear when I click another button, so that another swf can load. 我还希望单击另一个按钮时swf消失,以便可以加载另一个swf。 This code shows my swf, but it just "loops". 这段代码显示了我的swf,但是它只是“循环”。 And also it covers my menu (on the top of the page) so I can't click anywhere. 而且它涵盖了我的菜单(位于页面顶部),所以我无法单击任何位置。 What could I change in the code to fix this? 我可以在代码中进行哪些更改以解决此问题?

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

bilder_btn.addEventListener(MouseEvent.CLICK,  buttonClick)
function  buttonClick(e:MouseEvent):void
{
     try{
loader_mc.unloadAndStop();
} catch(e:Error) {
}
      var urlRequest : URLRequest = new  URLRequest("flickr.swf");
      loader_mc.load(urlRequest);
}
  1. Change loader_mc 's X and Y so that the loaded SWF does not cover your menu. 更改loader_mc的X和Y,以使加载的SWF不覆盖菜单。
  2. You could do better with reinitializing that loader_mc to load another SWF, that is, create a new Loader() , removeChild() the old loader, addChild() the new one, then load. 您可以通过重新初始化loader_mc来加载另一个SWF来loader_mc ,即,创建一个new Loader() ,旧的加载器removeChild() ,新的addChild()然后加载。

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

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