
CustomEvents page2
I imported Event Class. BulkImageLoaderEvent Class extends Event Class so that it can inherits all properties and methods from Event Class.
I import Bitmap Class because in used Bitmap data type in BulkImageLoaderEvent Class as I am working on images, I think I need to use bitmap data type.
public static const ALL_LOAD_COMPLETE:String="AllLoadComplete";
public static const SINGLE_LOAD_COMPLETE:String="SingleLoadComplete";
This defines your custom event
string constant. ie It defines type of your event.
Constructor function have some parameters, out of which $type, $bubbles, $cancelable are standard parameters of Event Class. Using super keyword we passed parameters to superclass ie Event Class.
Remaining two $paramArr ,$paramBit, we are going to use as per our use.
I put paramArr and paramBit as public so that I can access them out side this class with its instance.
clone() and toString() functions are belong to Event class and we override them with our two new variables. That’s it. Now lets attach it to our custom class to control its actions.
BulkImageLoader Class
Here we put our business logic to load all images.
BulkImageLoader.as
package
{
import flash.display.*;
import flash.events.*;
import flash.net.*
import BulkImageLoaderEvent
public class BulkImageLoader extends MovieClip
{
private var ImgArr:Array=new Array();
private var noOfImgLoaded=0;
private var currImgLoaded=0;
private var imgReq:URLRequest
private var imgurl:Loader
private var imgLoadedArray:Array=new Array();
public function BulkImageLoader(_ImgArr:Array)
{
ImgArr=_ImgArr
noOfImgLoaded=ImgArr.length-1
loadImage();
}
private function loadImage()
{
imgReq=new URLRequest(ImgArr[currImgLoaded])
imgurl=new Loader();
imgurl.load(imgReq);
imgurl.contentLoaderInfo.addEventListener(Event.COMPLETE,imgLoaded);
imgurl.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,imgLoadedError);
}
private function imgLoadedError(e:IOErrorEvent)
{
trace("Error")
imgLoadedArray.push(null);
dispatchEvent(new BulkImageLoaderEvent(BulkImageLoaderEvent.SINGLE_LOAD_COMPLETE,imgLoadedArray,null,true,false))
if(noOfImgLoaded==currImgLoaded)
{
dispatchEvent(new BulkImageLoaderEvent(BulkImageLoaderEvent.ALL_LOAD_COMPLETE,imgLoadedArray,null,true,false))
}
else
{
currImgLoaded++;
loadImage();
}
}
private function imgLoaded(e:Event)
{
imgLoadedArray.push(e.target.loader.content);
dispatchEvent(new BulkImageLoaderEvent(BulkImageLoaderEvent.SINGLE_LOAD_COMPLETE,imgLoadedArray,e.target.loader.content,true,false))
if(noOfImgLoaded==currImgLoaded)
{
dispatchEvent(new BulkImageLoaderEvent(BulkImageLoaderEvent.ALL_LOAD_COMPLETE,imgLoadedArray,e.target.loader.content,true,false))
}
else
{
currImgLoaded++;
loadImage();
}
}
}
}

