Flash AS3教程:ClassLoader类
2008-06-04 11:23:02 来源:WEB开发网我们的目的就达到了!
接下来是源代码!
package index.base.net{
import flash.display.Loader;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.EventDispatcher;
import flash.system.LoaderContext;
public class ClassLoader extends EventDispatcher{
public var url:String;
public var loader:Loader;
//构造函数
public function ClassLoader(obj:Object = null,lc:LoaderContext = null) {
if(obj != null){
if(obj is ByteArray){
loadBytes(obj as ByteArray,lc);
}else if(obj is String){
load(obj as String,lc);
}else{
throw new Error("参数错误,构造函数第一参数只接受ByteArray或String");
}
}
}
//加载
public function load(_url:String,lc:LoaderContext = null):void{
url = _url;
loader = new Loader;
loader.load(new URLRequest(url),lc);
addEvent();
}
//加载字节
public function loadBytes(bytes:ByteArray,lc:LoaderContext = null):void{
loader = new Loader;
loader.loadBytes(bytes,lc);
addEvent();
}
//开始侦听
private function addEvent():void{
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progressFun);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeFun);
}
//结束侦听
private function delEvent():void{
loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,progressFun);
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,completeFun);
}
//加载成功,发布成功事件
private function completeFun(e:Event):void {
delEvent();
dispatchEvent(e);
}
//加载过程
private function progressFun(e:ProgressEvent):void{
dispatchEvent(e);
}
//获取定义
public function getClass(className:String):Object {
return loader.contentLoaderInfo.applicationDomain.getDefinition(className);
}
//是否含有该定义
public function hasClass(className:String):Boolean {
return loader.contentLoaderInfo.applicationDomain.hasDefinition(className);
}
//清除
public function clear():void{
loader.unload();
loader = null;
}
}
}
- ››ASP.NET及JS中的cookie基本用法
- ››ASP.NET获取MS SQL Server安装实例
- ››asp.net实现调用百度pai 在线翻译英文转中文
- ››ASP.NET页面选项进行提示判断
- ››Asp.net定时执行程序
- ››ASP.NET中利用DataList实现图片无缝滚动
- ››ASP.NET验证控件RequiredFieldValidator
- ››ASP.NET中使用System.Net.Mail发邮件
- ››ASP.NET中获取用户控件中控件的ID
- ››ASP.NET中FileBytes写成文件并存档
- ››asp获取毫秒数
- ››asp.net报“INSERT INTO 语句的语法错误解决
更多精彩
赞助商链接