
CustomEvents page3
sachin patil
Hi, This is Sachin Patil, ActionScript developer. I am a Flash, Flex developer/designer toooo but coding is my passion.
I am using this community since i am playing with Flash.
I have completed my Bachelor Degree and Master Degree in Computer Science and Computer Application resp.
I loved JAVA but coincidentally i meet to Flash and I got crush on Flash.
Now i love Flash Coding.
I am satisfied with my life and Flash....
Happy living.........
I import all necessary classes. Also I import BulkImageLoaderEvent Class so that I can use this event. I declared all required variables. In constructor function I got Array which contain list of images path. loadImage() function loads images having path in ImgArr Array with index currImgLoaded. Imgurl Loader have EventListener to tell that image is loaded or there is file error.
On imgLoaded function I check with counter whether all images are loaded or not if not loaded I call loadImage() function again. So that I can load next image.
Now use of our custom event,
dispatchEvent(new BulkImageLoaderEvent(BulkImageLoaderEvent.SINGLE_LOAD_COMPLETE,imgLoadedArray,e.target.loader.content,true,false))
and
dispatchEvent(new BulkImageLoaderEvent(BulkImageLoaderEvent.ALL_LOAD_COMPLETE,imgLoadedArray,e.target.loader.content,true,false))
here I dispatched BulkImageLoaderEvent of type SINGLE_LOAD_COMPLETE. Where single image is loaded and passes e.target.loader.content as its paramBit variable’s data. If error occurs I passed null value.
And when all files loaded I dispatched BulkImageLoaderEvent of type ALL_LOAD_COMPLETE and passes Array of all loaded bitmaps as its paramArr variable’s data.
Timeline Code
mainTimeLine in fla file:
import BulkImageLoader;
var xmlReq:URLRequest=new URLRequest("gal.xml")
var xmlurl:URLLoader=new URLLoader();
var imgReqArr:Array=new Array();
var imgLabelArr:Array=new Array();
var startX=0;
var bulkImageLoader:BulkImageLoader;
var GalXML:XML
xmlurl.load(xmlReq);
xmlurl.addEventListener(Event.COMPLETE,xmlLoaded);
function xmlLoaded(e:Event)
{
GalXML=new XML(e.target.data);
trace(GalXML)
for(var i=0;i<GalXML.img.length();i++)
{
imgReqArr.push(GalXML.img[i].@src)
imgLabelArr.push(GalXML.img[i].@label)
}
bulkImageLoader=new BulkImageLoader(imgReqArr)
bulkImageLoader.addEventListener(BulkImageLoaderEvent.ALL_LOAD_COMPLETE,AllImgLoaded);
bulkImageLoader.addEventListener(BulkImageLoaderEvent.SINGLE_LOAD_COMPLETE,SingleImgLoaded);
}
function AllImgLoaded(e:BulkImageLoaderEvent)
{
addChild(e.paramArr[1])
}
function SingleImgLoaded(e:BulkImageLoaderEvent)
{
if(e.paramBit==null)
{
trace("bitmap data not present")
return;
}
addChild(e.paramBit)
}
Here I imported BulkImageLoader class so that I can use it.
Here I put my business logic. I loaded XML file , parse it and while creating instance of BulkImageLoader Class I sent an Array which contain path of all files.
And finally I assign BulkImageLoaderEvent of types ALL_LOAD_COMPLETE and SINGLE_LOAD_COMPLETE.
When ALL_LOAD_COMPLETE event occurs I got all bitmaps which are loaded through e.paramArr
And current loaded bitmap through e.paramBit in SINGLE_LOAD_COMPLETE event type.
That is the power of custom event. Now I can reuse this code whenever I want.
-Regards
http://www.sachinpatilaction.blogspot.com/
Spread The Word
1 Response to "Create your own Events" 
|
said this on 15 Feb 2012 1:51:00 AM CDT
Very useful for the begin
|


Author/Admin)