[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文件(假设为1.swf)加载另一个SWF文件(假设为2.swf),并且1.swf调用2.swf文件里的方法,方法如下:
1.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: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("朋友");
}
package{
import flash.display.Sprite;
public class MainForm extends Sprite{
public function MainForm(){
}
public function sayHello(str){
trace("hello!"+str);
}
}
}
import flash.display.Sprite;
public class MainForm extends Sprite{
public function MainForm(){
}
public function sayHello(str){
trace("hello!"+str);
}
}
}