package{ import flash.display.*; import flash.events.Event; import flash.net.URLRequest; public class LoadJPG extends Sprite{ private var myLoader:Loader; public function LoadJPG(){ myLoader=new Loader(); myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeListener); myLoader.contentLoaderInfo.addEventListener(Event.INIT,initListener); myLoader.load(new URLRequest("fengjing.jpg")); }//end of constructor function LoadJPG private function completeListener(e:Event):void{ trace("This is from Event.COMPLETE listener"); trace(myLoader.content.width); trace(myLoader.getChildAt(0).height); trace(e.target.content.rotation); trace("添加到显示列表前 : ",myLoader.numChildren);//1 addChild(myLoader.content); trace("添加到显示列表后 : ",myLoader.numChildren);//0 }//end of function completeListener private function initListener(e:Event):void{ trace("This is from Event.INIT listener"); trace(myLoader.content.width); trace(myLoader.getChildAt(0).height); trace(e.target.content.rotation); }//end of function initListener }//end of class LoadJPG }//end of package
例如,在加载影片或动画的第一帧时将调度 Event.INIT。然后,影片将可供访问并可添加到显示列表中。不过,下载完整的影片可能需要花更长的时间。只有在加载了完整的影片之后才会调度 Event.COMPLETE。
init 事件始终在 complete 事件之前。
访问用Loader加载进来的显示资源的时候,通常有3种办法,比如,myLoader是Loader类型的实例,要访问其加载的内容,可以这样:
1,myLoader.content;//直接访问实例的content
2,myLoader.getChildAt(0);//被加载的资源是myLoader的唯一孩子
3,e.target.content;//在侦听函数里面通过事件的目标对象访问
如果要为Loader添加侦听,必须通过Loader的实例变量contentLoaderInfo注册,contentLoaderInfo变量提供了对它装载资源的LoaderInfo对象的一个引用。而不能直接在Loader的实例上添加侦听!
以下代码简单展示了访问装载资源对象的方法和添加侦听的方法,有一个小疑惑啊,事件类型Event.COMPLETE和Event.INIT有什么区别,只知道前者是在加载结束之后触发,后者是在加载初始化后触发。牢记一点Event.COMPLETE永远发生的比Event.INIT晚 ,所以是不是在更多的情况下考虑使用Event.COMPLETE?
参考书对Event.INIT的解释如下
1, 对位图而言,实例化发生于当外部文件已经完全装载的时候。在那个时期,被装载的像素数据自动地被放置在一个BitmapData对象中,然后它被关联于一 个新的Bitmap对象,改Bitmap对象表示被装载的图像。(是不是对位图而言Event.INIT跟Event.COMPLETE是一样的?)
2,对于swf文件,实例化发生于当在帧1的所有资源和类(包括.swf的主类)已经被接收到的时候。在那个时期,ActionScript创建.swf主类的一个实例,并执行它的构造器。该主类实例表示被装载的.swf文件。
注 意,千万不要在初始化完成之前(Event.INIT触发之前)或者加载完成之前(Event.COMPLETE触发之前)试图访问被加载的资源。此时会 报错,如果用myLoader.content访问,content此时为空,如果用myLoader.getChildAt(0)访问则报错,错误 为:RangeError:Error #2006
当被装载的资源对象添加到一个新的DisplayObjectContainer中,被装载的资源自动从它原来的父亲容器Loader对象中移除!
发表评论
-
AS3 父SWF与子SWF之间传值
2011-02-20 15:19 2586FLASH中 父SWF加载子SWF并向子SWF传值在很多应用上 ... -
flash as3.0 被加载的swf 控制主swf文件触发事件
2011-02-19 14:48 2988比如有两个swf文件 1.swf,2.swf 1.swf ... -
一些很有创意的导航栏设计,给大家分享下。
2011-02-19 11:08 1546希望对各位同学有所帮助。啊哦………… 陆续完善i ... -
浅谈webgame游戏开发技术要点
2011-02-19 11:02 965写这些只是想和大家交 ... -
aswing
2011-02-19 10:43 829AsWing是一套UI组件框架,纯ActionScript开发 ... -
as3加载外部XML文件
2011-02-18 19:50 1414加载过程如下: 1.使用URLRequ ... -
如何保护swf文件不被反编译软件破解?
2011-02-18 19:42 2135How to protect SWFs from decomp ... -
45度地图编辑器及游戏开发心得
2011-02-15 19:12 1390转载 这个编辑器是本人为公司项目专门开发 的一个功能比较齐 ... -
BulkLoader开源文件加载类
2011-02-09 22:10 1189BulkLoader是一个不错且使用简单的开源加载类, ... -
社区客户端开发技术总结
2011-01-29 22:57 824不管是什么样的项目,都会拆分成一个一个小的模块。最终实现都是些 ... -
“神之惩戒”--国内MMORPG游戏的困局1
2011-01-28 15:13 753《神之惩戒——MMOR ... -
adobe alchemy资料整理
2011-01-28 14:56 2412Adobe 自从2007年中推出了AS3支持 ... -
hitTest(BitmapData.hitTest 方法)
2011-01-25 18:14 1141public hitTest(firstPoint:Poi ... -
AS3使用外部SWF文件的库文件
2011-01-25 15:32 1431在swf文件中使用外部swf文件的库文件,从而达到类似素材 ... -
Flash摄像头游戏课件设计与开发
2011-01-25 11:07 1181[导读] Flash摄像头游戏课件设计与开发 ... -
AS3图像复制BitmapData.copyPixels()
2011-01-22 16:35 1910//舞台属性设置 stage.align ... -
ps样式介绍
2011-01-22 14:32 824PS样式就是效果的集合。“窗口”“样式”就可以打开样式面板。里 ... -
获取当前SWF的绝对路径
2011-01-20 19:22 1345首先 ,说明我测试的系统地址和网络地址的情况: 某电脑 ... -
PureMVC中观察者模式运用
2011-01-20 09:36 1252刚一个开始看PureMVC,一个字乱,摸不着头脑,不过这个要慢 ... -
获取当前SWF的当前路径
2011-01-19 20:00 1416首先 ,说明我测试的系统地址和网络地址的情况: 某电脑 ...
相关推荐
4.1.13 UPNP E INIT FAILED [-117] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.1.14 UPNP E BAD HTTPMSG [-119] . . . . . . . . . . . . . . . . . . . . . . . . . ....
xmlLoader.addEventListener(Event.COMPLETE,xmlLoaderCompleteHandler); } private function xmlLoaderCompleteHandler(event:Event):void { xml=new XML(event.target.data); title=xml.song.@...
lrcLoader.addEventListener(Event.COMPLETE,loadCompleteHandler); stage.addEventListener(Event.ENTER_FRAME,soundPlayingHandler); this.addEventListener(Event.ENTER_FRAME,creatSpectrum); } ...
.addEventListener("complete",a.onComplete))}var a=createjs.extend(AbstractTween,createjs.EventDispatcher);a._setPaused=function(a){return createjs.Tween._register(this,a),this},a.setPaused=createjs....
Table of Contents Summary of gdb . . . . . . . . ....Free Software ....Free Software Needs Free Documentation ....Contributors to gdb....1 A Sample gdb Session ....2 Getting In and Out of gdb ....2.1 Invoking gdb ....
Python参考手册,官方正式版参考手册,chm版。以下摘取部分内容:Navigation index modules | next | Python » 3.6.5 Documentation » Python Documentation contents What’s New in Python ...
:)26/3/981.6.1- Added a FUNCFileName private variable to manage the complete path of the attached file. I receive problems reports with this, it work now ?.- Reduced the line sleep to 30 (tell me if ...
Release Notes some small control sidebar fixes fixed content height calculation with overlapping control sidebar fixed collapse/show functions (functions was ...For the complete changelog look here.
J()){_=_||setInterval(function(){if(V[N].readyState=="complete")clearInterval(_);U(null,true)},50);return}if($dp.status==0){$dp.status=1;L.el=T;I(L,true)}else return}else if(L.eCont){L.eCont=$dp.$(L....
;;;;;;;;... 1.... 2.... 3.... 4.... 5.... 6.... The syntax of the file is extremely simple.... Section headers (e.g.... at runtime.... There is no name validation.... (e.g.... previously set variable or directive (e.g....
The init() Function 77 The display() Function 78 Widget Callbacks 81 What Are They? 81 What Are They Used For? 82 Callback Arguments (Widget Function Data) 82 Widget Placement 84 Widget Variables 86 ...
SCGCQ00324525 Defect MegaCLI: MFI_STAT_NOT_FOUND returns when retrieving the FW event log. SCGCQ00325890 Defect CLI/Segmentation fault while running pdlist and cfgdsply in CentOS SCGCQ00326673 Defect ...
- converted the complete hdimage stuff to the new 'hdimage' plugin - new hdimage method get_capabilities() that can return special flags - vmware3, vmware4 and vvfat classes now return HDIMAGE_HAS_...