home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 149 / MOBICLIC149.ISO / pc / DATA / DSS149 / DSS149_01 / DSS149_01.swf / scripts / com / milanpresse / capsule / LoadLib.as < prev   
Text File  |  2012-11-21  |  4KB  |  135 lines

  1. package com.milanpresse.capsule
  2. {
  3.    import flash.display.Loader;
  4.    import flash.events.Event;
  5.    import flash.events.HTTPStatusEvent;
  6.    import flash.events.IEventDispatcher;
  7.    import flash.events.IOErrorEvent;
  8.    import flash.events.ProgressEvent;
  9.    import flash.net.URLRequest;
  10.    import flash.system.ApplicationDomain;
  11.    import flash.system.LoaderContext;
  12.    
  13.    public class LoadLib
  14.    {
  15.        
  16.       
  17.       private var _swfPath:String = null;
  18.       
  19.       private var _classPath:String = null;
  20.       
  21.       private var _callback:Function = null;
  22.       
  23.       private var _loader:Loader;
  24.       
  25.       private var _lib = null;
  26.       
  27.       private var _params:Object = null;
  28.       
  29.       public function LoadLib(classPath:String = null, swfPath:String = null, callback:Function = null, params:Object = null)
  30.       {
  31.          super();
  32.          this._params = params;
  33.          this._swfPath = swfPath;
  34.          this._classPath = classPath;
  35.          this._callback = callback;
  36.          this.init();
  37.       }
  38.       
  39.       private function init() : void
  40.       {
  41.          if(this._classPath == null || ApplicationDomain.currentDomain.hasDefinition(this._classPath) == false)
  42.          {
  43.             this.loadLib(this._swfPath);
  44.          }
  45.          else
  46.          {
  47.             this.libLoaded();
  48.          }
  49.       }
  50.       
  51.       private function libLoaded() : void
  52.       {
  53.          this.libInitialised();
  54.       }
  55.       
  56.       private function libInitialised() : void
  57.       {
  58.          if(this._callback != null)
  59.          {
  60.             this._callback();
  61.          }
  62.       }
  63.       
  64.       private function loadLib(_swfPath:String) : void
  65.       {
  66.          this._loader = new Loader();
  67.          this.loaderAddListeners(this._loader.contentLoaderInfo);
  68.          this._loader.load(new URLRequest(_swfPath),new LoaderContext(false,ApplicationDomain.currentDomain));
  69.       }
  70.       
  71.       private function loaderAddListeners(dispatcher:IEventDispatcher) : void
  72.       {
  73.          dispatcher.addEventListener(Event.COMPLETE,this.completeHandler);
  74.          dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS,this.httpStatusHandler);
  75.          dispatcher.addEventListener(Event.INIT,this.initHandler);
  76.          dispatcher.addEventListener(IOErrorEvent.IO_ERROR,this.ioErrorHandler);
  77.          dispatcher.addEventListener(Event.OPEN,this.openHandler);
  78.          dispatcher.addEventListener(ProgressEvent.PROGRESS,this.progressHandler);
  79.          dispatcher.addEventListener(Event.UNLOAD,this.unLoadHandler);
  80.       }
  81.       
  82.       private function loaderRemoveListeners(dispatcher:IEventDispatcher) : void
  83.       {
  84.          dispatcher.removeEventListener(Event.COMPLETE,this.completeHandler);
  85.          dispatcher.removeEventListener(HTTPStatusEvent.HTTP_STATUS,this.httpStatusHandler);
  86.          dispatcher.removeEventListener(Event.INIT,this.initHandler);
  87.          dispatcher.removeEventListener(IOErrorEvent.IO_ERROR,this.ioErrorHandler);
  88.          dispatcher.removeEventListener(Event.OPEN,this.openHandler);
  89.          dispatcher.removeEventListener(ProgressEvent.PROGRESS,this.progressHandler);
  90.          dispatcher.removeEventListener(Event.UNLOAD,this.unLoadHandler);
  91.       }
  92.       
  93.       private function completeHandler(event:Event) : void
  94.       {
  95.          trace("completeHandler: " + event);
  96.          this.loaderRemoveListeners(this._loader.contentLoaderInfo);
  97.          this.libLoaded();
  98.       }
  99.       
  100.       private function httpStatusHandler(event:HTTPStatusEvent) : void
  101.       {
  102.          trace("httpStatusHandler: " + event);
  103.       }
  104.       
  105.       private function initHandler(event:Event) : void
  106.       {
  107.          trace("initHandler: " + event);
  108.       }
  109.       
  110.       private function ioErrorHandler(event:IOErrorEvent) : void
  111.       {
  112.          trace("ioErrorHandler: " + event);
  113.       }
  114.       
  115.       private function openHandler(event:Event) : void
  116.       {
  117.          trace("openHandler: " + event);
  118.       }
  119.       
  120.       private function progressHandler(event:ProgressEvent) : void
  121.       {
  122.          trace("progressHandler: bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
  123.       }
  124.       
  125.       private function unLoadHandler(event:Event) : void
  126.       {
  127.          trace("unLoadHandler: " + event);
  128.       }
  129.       
  130.       public function destroy() : void
  131.       {
  132.       }
  133.    }
  134. }
  135.