[as3.0]调用加载的SWF文件的函数

View Code
 1 package
 2 {
 3     import flash.display.Loader;
 4     import flash.display.Sprite;
 5     import flash.events.Event;
 6     import flash.net.URLRequest;
 7     import flash.system.ApplicationDomain;
 8     import flash.system.LoaderContext;
 9     import flash.system.SecurityDomain;
10     import flash.utils.getDefinitionByName;
11     
12     public class Test extends Sprite
13     {
14         public function Test()
15         {
16             var url:URLRequest=new URLRequest("asset/securityTest.swf");
17             var loadercontext:LoaderContext=new LoaderContext();
18             loadercontext.applicationDomain= ApplicationDomain.currentDomain;
19             
20             var loader:Loader=new Loader();
21             loader.load(url,loadercontext);
22             this.addChild(loader);
23 //            var loader:Loader=new Loader();
24 //            loader.load(url);
25             loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onload);
26             
27         }
28         private function onload(e:Event):void
29         {
30 //            var myclass:Class=getDefinitionByName("securityTest") as Class;
31 //            trace(typeof(myclass));
32 //            var myc:Object=new myclass();
33 //            trace(myc["out"]);
34             e.target.content.out();
35             
36         }
37     }
38 }

[as3.0]调用加载的SWF文件的函数

 
 在使用as3.0中,想要一个SWF文件(假设为1.swf)加载另一个SWF文件(假设为2.swf),并且1.swf调用2.swf文件里的方法,方法如下:
1.swf:
var  url:String  =   " 2.swf " ;
var  req:URLRequest  =   new  URLRequest(url);
var  myLoader:Loader  =   new  Loader();
myLoader.load(req);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);

function  completeHandler(evt) {
        evt.target.content.sayHello("朋友");
}

2.swf:
package {
        import flash.display.Sprite;
        
        public class MainForm extends Sprite{
                public function MainForm(){
                        
                }

                public function sayHello(str){
                        trace("hello!"+str);
                }

        }

}

转载于:https://www.cnblogs.com/YY-1028/archive/2012/04/26/2471263.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值