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
Wrap
Text File
|
2012-11-21
|
4KB
|
135 lines
package com.milanpresse.capsule
{
import flash.display.Loader;
import flash.events.Event;
import flash.events.HTTPStatusEvent;
import flash.events.IEventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
public class LoadLib
{
private var _swfPath:String = null;
private var _classPath:String = null;
private var _callback:Function = null;
private var _loader:Loader;
private var _lib = null;
private var _params:Object = null;
public function LoadLib(classPath:String = null, swfPath:String = null, callback:Function = null, params:Object = null)
{
super();
this._params = params;
this._swfPath = swfPath;
this._classPath = classPath;
this._callback = callback;
this.init();
}
private function init() : void
{
if(this._classPath == null || ApplicationDomain.currentDomain.hasDefinition(this._classPath) == false)
{
this.loadLib(this._swfPath);
}
else
{
this.libLoaded();
}
}
private function libLoaded() : void
{
this.libInitialised();
}
private function libInitialised() : void
{
if(this._callback != null)
{
this._callback();
}
}
private function loadLib(_swfPath:String) : void
{
this._loader = new Loader();
this.loaderAddListeners(this._loader.contentLoaderInfo);
this._loader.load(new URLRequest(_swfPath),new LoaderContext(false,ApplicationDomain.currentDomain));
}
private function loaderAddListeners(dispatcher:IEventDispatcher) : void
{
dispatcher.addEventListener(Event.COMPLETE,this.completeHandler);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS,this.httpStatusHandler);
dispatcher.addEventListener(Event.INIT,this.initHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR,this.ioErrorHandler);
dispatcher.addEventListener(Event.OPEN,this.openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS,this.progressHandler);
dispatcher.addEventListener(Event.UNLOAD,this.unLoadHandler);
}
private function loaderRemoveListeners(dispatcher:IEventDispatcher) : void
{
dispatcher.removeEventListener(Event.COMPLETE,this.completeHandler);
dispatcher.removeEventListener(HTTPStatusEvent.HTTP_STATUS,this.httpStatusHandler);
dispatcher.removeEventListener(Event.INIT,this.initHandler);
dispatcher.removeEventListener(IOErrorEvent.IO_ERROR,this.ioErrorHandler);
dispatcher.removeEventListener(Event.OPEN,this.openHandler);
dispatcher.removeEventListener(ProgressEvent.PROGRESS,this.progressHandler);
dispatcher.removeEventListener(Event.UNLOAD,this.unLoadHandler);
}
private function completeHandler(event:Event) : void
{
trace("completeHandler: " + event);
this.loaderRemoveListeners(this._loader.contentLoaderInfo);
this.libLoaded();
}
private function httpStatusHandler(event:HTTPStatusEvent) : void
{
trace("httpStatusHandler: " + event);
}
private function initHandler(event:Event) : void
{
trace("initHandler: " + event);
}
private function ioErrorHandler(event:IOErrorEvent) : void
{
trace("ioErrorHandler: " + event);
}
private function openHandler(event:Event) : void
{
trace("openHandler: " + event);
}
private function progressHandler(event:ProgressEvent) : void
{
trace("progressHandler: bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
}
private function unLoadHandler(event:Event) : void
{
trace("unLoadHandler: " + event);
}
public function destroy() : void
{
}
}
}