- 积分
- 136401
- 注册时间
- 2014-12-27
- 最后登录
- 2026-1-24
- 在线时间
- 605 小时
- 威望
- 562
- 贡献
- 29
- 金币
- 52903
- 钢镚
- 1422
- 交易凭证
- 1
- 分享
- 0
- 精华
- 33
- 帖子
- 2094
- 主题
- 1742
TA的每日心情 | 擦汗 2018-4-10 15:18 |
|---|
签到天数: 447 天 [LV.9]以坛为家II
超级版主
    
- 威望
- 562
- 贡献
- 29
- 金币
- 52903
- 钢镚
- 1422
 
|
以前取出用Embed嵌入的资源都用这样的方法:
- [Embed(source="assets/project.swf", symbol="image1")]
- public var img:Class;
复制代码 然后实例化使用,今天打断点发现用Embed嵌入的资源运行时进入了MovieClipLoaderAsset类,看一下其构造方法:
- public function MovieClipLoaderAsset()
- {
- super(); var loaderContext:LoaderContext = new LoaderContext();
- loaderContext.applicationDomain = new
- ApplicationDomain(ApplicationDomain.currentDomain);
-
- // in AIR...
- // when embedding a SWF using @Embed, you are actively asking for the SWF
- // to be executed, otherwise the SWF will fail loading due to
- // Loader.allowLoadBytesCodeExecution.
- //
- // this property prevents accidentally loading a potentially dangerous
- // SWF into the application sandbox.
- //
- // since this property is indirectly accessed, this should be revisited
- // after AIR 1.x, as it may become deprecated
- if ("allowLoadBytesCodeExecution" in loaderContext)
- loaderContext["allowLoadBytesCodeExecution"] = true; loader = new Loader();
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
- completeHandler);
- loader.loadBytes(movieClipData, loaderContext);
- addChild(loader);
- }
-
复制代码 发现添加了一个loader,于是发现只要把loader取出来就可以了
- [Embed(source="assets/project.swf")]
- public var swf:Class;
-
- private function onLoadComplete(event:Event):void
- {
- var cls:Class = event.target.applicationDomain.getDefinition("image1") as Class;
- var bmp:BitmapData = new cls();
- }
-
- private function init():void
- {
- var c:* = new swf();
- (c.getChildAt(0) as Loader).contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
- }
复制代码 取出图片成功
不过Embed的方式其实效率并不是太高,而且还增加主工程的大小,所以还是建议用loader来加载资源
|
|