as3使用外部加载类库
发布:Coamy | 发布时间: 2009年9月15日as3使用外部加载类库,主模块main.swf,被调用模块lib.swf,
lib.fla的文档类Lib.as中,假设已定义的模块有Module0.as,Module1.as
package com{ import com.Module1; import com.Module2; //import 模块 public class Lib extends MovieClip{ private var module1:Module1; private var modlue2:Module2; //要定义一个该类型的变量}}
在main文档类中
function init():void{loader = new Loader;loader.contentLoaderInfo.addEventListener("complete",getRefer);loader.load(new URLRequest("lib.swf"));}function getRefer(e:Event):void{var module0:Class = loader.contentLoaderInfo.applicationDomain.getDefinition("com.Module") as Class;//其他类似 可以得到Lib中已经被声明过的类:Lib,Module0,Module1...//getDefinition()中的参数要包括被加载类的包名//new module0();}
这是as3的反射,你可以在网上根据关键词查询更多的例子;
至于要加载Lib.swf中的元件是同样的道理,元件的linkage必须export for ActionScript 定义一个Class类名例如 Test_mc
加载它如同上面加载类
function getRefer(){...var test_mc:Class = loader.contentLoaderInfo.applicationDomain.getDefinition("Test_mc") as Class;//这里getDefinition()中的参数不需要要包括包名addChild(new test_mc);}
发布:Coamy | 分类:AS3 | 评论:0 | 引用:0 | 浏览:
| TrackBack引用地址
- 相关文章:
Actionscript 3.0基础教程-类的编写 (2009-9-14 20:1:29)
flash接收外部参数的问题 (2009-9-12 16:28:25)
Ubuntu-Firefox中Flash播放器乱码解决 (2009-5-10 10:41:8)
发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。





