标签:as3 加载器
最近鼓捣除了一个加载器。可以分布式地加载文本文件以及SWF文件。本人将它写成了一个Flex库。本着共同进步的目的,我将其分享出来。
测试结果 :
控制台:
测试资源:
关于 Flash(SWF)美术资源的介绍:
关于测试的核心代码 :
package { import com.DispalyLoader; import com.LoaderManager; import com.ResLibrary; import com.TextObjectLoader; import flash.display.MovieClip; import flash.display.Sprite; import flash.events.ProgressEvent; import flash.system.ApplicationDomain; import flash.system.LoaderContext; public class MyTest extends Sprite { [SWF(frameRate=‘30‘ , width=‘1280‘ , height=‘720‘, backgroundColor=‘0x001119‘, pageTitle="TEST")] public function MyTest() { var $urlHttp : String = stage.loaderInfo.url; var $index : int = $urlHttp.indexOf( "MyTest" ); var http : String = $urlHttp.substring( 0 , $urlHttp.indexOf( "MyTest" ) ); trace( http ); var $loader : LoaderManager = new LoaderManager(true,true); var $txtRes : TextObjectLoader = new TextObjectLoader( this.textCallback , http + "config.xml" ); var $txtLanRes : TextObjectLoader = new TextObjectLoader( this.textCallback , "../asset/xml/lan.xml" ); var $display : DispalyLoader = new DispalyLoader( this.displayCallBack,"../asset/swf/Test.swf" , ApplicationDomain.currentDomain); var $display1 : DispalyLoader = new DispalyLoader( this.displayCallBack,"../asset/swf/Others.swf" , ApplicationDomain.currentDomain); $loader.append( $txtRes ); $loader.append( $txtLanRes ); $loader.append( $display ); $loader.append( $display1 ); $loader.startLoader(); } private function textCallback( $type : String , $data : Object , $extends : Object = null ) : void { switch( $type ) { case "COMPLETE": trace( "http : " + $data + " 数据 : " + $extends as String ); break; case "PROGRESS": var $progress : ProgressEvent = $data as ProgressEvent; trace("加载进度 : " + ($progress.bytesLoaded / $progress.bytesTotal ) ); break; } } private function displayCallBack( $type : String , $data : Object , $extends : Object = null ) : void { switch( $type ) { case "LOADED": ResLibrary.instance.addSwf( $data as String , ( $extends as LoaderContext ).applicationDomain ); // 测试 var $swfArr : Array = ( $data as String ).split( "/" , ( $data as String ).length ); var $mc : MovieClip = null; switch($swfArr[$swfArr.length-1]) { case "Test.swf": $mc = ResLibrary.instance.getMovieClip( "MCC" ); break; case "Others.swf": $mc = ResLibrary.instance.getMovieClip( "MCQ" ); break; } stage.addChild( $mc ); break; case "LOADED_ERROR": break; case "PROGRESS": break; } } } }
本文出自 “Better_Power_Wisdom” 博客,请务必保留此出处http://aonaufly.blog.51cto.com/3554853/1835446
标签:as3 加载器
原文地址:http://aonaufly.blog.51cto.com/3554853/1835446