/ Published in: ActionScript 3

The Loader class is used for handling Bitmap data such as jpegs, pngs and gifs. The only handlers most will find relevant are progressHandler and onCompleteHandler but I listed all of the available ones for people interested in creating bulletproof apps.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/******************************** Event Listeners ********************************/ var imgLoader:Loader = new Loader(); initBasicListeners( imgLoader ); imgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler, false, 0, true); imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler, false, 0, true); imgLoader.load(new URLRequest(asset)); //These Event Listeners are used a lot so let's try to minimize redundancies function initBasicListeners(dispatcher:IEventDispatcher):void { dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler, false, 0, true); dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler, false, 0, true); dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true); } /******************************** Event Handlers ********************************/ function httpStatusHandler (e:Event):void { //trace("httpStatusHandler:" + e); } function securityErrorHandler (e:Event):void { trace("securityErrorHandler:" + e); } function ioErrorHandler(e:Event):void { trace("ioErrorHandler: " + e); } function progressHandler(e:Event):void { trace(e.currentTarget.bytesLoaded + " / " + e.currentTarget.bytesTotal); } function onCompleteHandler (e:Event):void { trace("imgCompleteHandler:" + e.currentTarget.content + " " + e.currentTarget.loader); addChild( e.currentTarget.loader ); }
Comments
