外部加载的swf或jpg的复制方法
1. 设置存放swf或jpg的容器
1 2 3 4 5 |
var _ld1:Loader = new Loader(); var _ld2:Loader = new Loader(); _ld1.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandle1); _ld2.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandle2); ... ... |
2. 用URLLoader类加载外部swf或jpg文件
1 2 3 4 5 6 |
var url:String = "test.jpg"; var byteLoader:URLLoader = new URLLoader(); byteLoader.dataFormat = URLLoaderDataFormat.BINARY; configureListeners(byteLoader); byteLoader.load(new URLRequest(url)); ... ... |
3. 定义byteLoader的各种事件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
private function configureListeners(dispatcher:IEventDispatcher):void { dispatcher.addEventListener(Event.COMPLETE, completeHandle); dispatcher.addEventListener(Event.OPEN, openHandle); dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandle); dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandle); dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandle); dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandle); } private function completeHandle(e:Event):void { //将数据移交给_ld1和_ld2 _ld1.loadBytes(e.target.data); _ld2.loadBytes(e.target.data); } private function openHandle(e:Event):void { //trace("openHandler: " + e); } private function progressHandle(e:ProgressEvent):void { //trace("progressHandler loaded:" + e.bytesLoaded + " total: " + e.bytesTotal); } private function securityErrorHandle(e:SecurityErrorEvent):void { //trace("securityErrorHandler: " + e); } private function httpStatusHandle(e:HTTPStatusEvent):void { //trace("httpStatusHandler: " + e); } private function ioErrorHandle(e:IOErrorEvent):void { //trace("ioErrorHandler: " + e); } |
4. 数据接收后的处理
1 2 3 4 5 6 7 8 |
private function completeHandle1(e:Event):void { //_ld1获得数据后的处理 ... ... } private function completeHandle2(e:Event):void { //_ld2获得数据后的处理 ... ... } |