Return to Snippet

Revision: 5101
at March 24, 2008 11:09 by chrisaiv


Updated Code
/********************************
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 );
}

Revision: 5100
at March 24, 2008 11:05 by chrisaiv


Updated Code
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));

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);
}

function onCompleteHandler (e:Event):void
{
	trace("imgCompleteHandler:" + e.currentTarget.content + " "  + e.currentTarget.loader);
    addChild(imgLoader);
}
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);
}

Revision: 5099
at February 22, 2008 02:18 by chrisaiv


Updated Code
var imgLoader:Loader = new Loader();
    imgLoader.addEventListener(Event.COMPLETE, onCompleteHandler);
    imgLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
    imgLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
    imgLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    imgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
    imgLoader.load(new URLRequest(asset));

    addChild(imgLoader);

function onCompleteHandler (e:Event):void
{
	trace("imgCompleteHandler:" + e.currentTarget.content + " "  + e.currentTarget.loader);
}
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);
}

Revision: 5098
at February 20, 2008 00:41 by chrisaiv


Updated Code
var imgLoader:Loader = new Loader();
    imgLoader.addEventListener(Event.COMPLETE, onCompleteHandler);
    imgLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
    imgLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
    imgLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    imgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
    imgLoader.load(new URLRequest(asset));

    addChild(imgLoader);

function onCompleteHandler (e:Event):void
{
	trace("imgCompleteHandler:" + e.currentTarget);
}
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);
}

Revision: 5097
at February 20, 2008 00:33 by chrisaiv


Updated Code
var imgLoader:Loader = new Loader();
    imgLoader.addEventListener(Event.COMPLETE, onCompleteHandler);
    imgLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
    imgLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
    imgLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    imgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
    imgLoader.load(new URLRequest(asset));

    addChild(imgLoader);

function onCompleteHandler	(e:Event):void
{
	trace("imgCompleteHandler:" + e.currentTarget);
}
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);
}

Revision: 5096
at February 11, 2008 17:35 by chrisaiv


Updated Code
var imgLoader:Loader = new Loader();
    imgLoader.addEventListener(Event.COMPLETE, imgCompleteHandler);
    imgLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
    imgLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
    imgLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    imgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
    imgLoader.load(new URLRequest(asset));

    addChild(imgLoader);

function imgCompleteHandler	(e:Event):void
{
	trace("imgCompleteHandler:" + e.currentTarget);
}
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);
}

Revision: 5095
at February 11, 2008 17:33 by chrisaiv


Initial Code
var imgLoader:Loader = new Loader();
	imgLoader.addEventListener(Event.COMPLETE, imgCompleteHandler);
	imgLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
	imgLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
	imgLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
	imgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
	imgLoader.load(new URLRequest(asset));

	addChild(imgLoader);

function imgCompleteHandler	(e:Event):void
{
	trace("imgCompleteHandler:" + e.currentTarget);
}
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);
}

Initial URL

                                

Initial Description
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.

Initial Title
AS3: Using Loader for SWFs, JPEGs, GIF, and PNGs

Initial Tags

                                

Initial Language
ActionScript 3