项目需要运行时共享库项目,以前都是解压缩swc拿到libraryt.swf,加载进内存。其实想想也是可以加载swc文件,不建议使用
package { import com.common.utils.Reflection; import com.common.zip.fzip.FZip; import com.common.zip.fzip.FZipFile; import flash.display.Loader; import flash.display.Sprite; import flash.events.Event; import flash.net.URLRequest; import flash.system.ApplicationDomain; import flash.system.LoaderContext; import flash.utils.ByteArray; [SWF(width = "400",height = "300",backgroundColor="#CCCCCC")] public class LoadSWCExample extends Sprite { private var fZipLoader :FZip; public function LoadSWCExample() :void { fZipLoader = new FZip(); fZipLoader.load(new URLRequest("GameCommon.swc")); fZipLoader.addEventListener(Event.COMPLETE, onComplete); } /** *加载swc完毕 * @param evt * */ private function onComplete(evt:Event):void { var swfData :ByteArray = fZipLoader.getFileByName("library.swf").content;//取swf内容 fZipLoader.removeEventListener(Event.COMPLETE, onComplete); fZipLoader = null; // var loader :Loader = new Loader(); loader.loadBytes(swfData,new LoaderContext(false,ApplicationDomain.currentDomain));//加载到域 loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e :Event):void{ trace(Reflection.createInstance("com.global.GlobalDef")); }); } } }
FZip,FZipFile 为 claus-fzip共享项目 自己下载