在as3中,如果父swf加载了一个子swf,而子swf又加载了一个txt文件,那么父swf如何知道子swf何时加载txt文件完成了呢?
子swf中的代码:
var urlrequest:URLRequest=new URLRequest("a.txt");
var loader:URLLoader=new URLLoader();
loader.load(urlrequest);
loader.addEventListener(Event.COMPLETE,com);
function com(evt) {
dispatchEvent(new Event("go"));
}
输出为loadtxt.swf
父swf中的代码:
var urlrequest:URLRequest=new URLRequest("loadtxt.swf");
var loader:Loader=new Loader();
loader.load(urlrequest);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,com);
function com(evt) {
evt.target.content.addEventListener("go", testHandler)
}
addChild(loader);
function testHandler(evt) {
trace(1);
}
这样当子swf加载txt完成时,父swf就会侦听到。
================
大家都喜欢在flex或eclipse中编写actionscript代码,在flash cs中制作UI与影片剪辑动画。
如果要把flash cs中的UI与动画添加到flex与eclipse项目中,常用的方法有两种:
1. 可以把UI与动画输出为swc文件,在项目中调用;
2. 在flex中,可以embed需要的UI元素或动画。
这两种方法调用起来简单,但是更新UI与动画的时候,就比较麻烦,需要重新输出UI与动画,再重新编译项目。
如果再遇到需要在线更换皮肤,就更行不通了。 外调皮肤可以解决上面的问题,外调皮肤也有两个简单的方案。
*加载到子域
var albumSkin:Object;
var __albumSkin:Class;
var url:String;
var loadSkin:Loader = new Loader();
var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
loadSkin.load(new URLRequest(url),context);
loadSkin.contentLoaderInfo.addEventListener(Event.COMPLETE,skinLoadedFunc);
private function skinLoadedFunc(e:Event):void{
__albumSkin = e.target.applicationDomain.getDefinition("AlbumSkin") as Class;
albumSkin = new __albumSkin();
dispatchEvent(new Event("skinLoaded"));
trace("[Skin loaded successfully!]");
}
*执行加载进来的swf中的方法
var skin:Sprite;
var loader:Loader = new Loader();
loader.load(new URLRequest(url));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
private function completeHandler(e:Event):void {
skin = e.target["content"].getSkin();
}
也可以参看一下这篇文章,请得比较深一点:AS3应用程序模块化开发与ApplicationDomain