dispatchEvent, i love you

January 28th, 2009

Yes, im loving so much the ‘dispatchEvent’. Understanding the why… I am working on Flash site using AMFPHP for one Hospital, into the site have some galleries that show medical team, the hospital and others. 

The Problem:
When i did the ‘for’ for create thumbs of the gallery i put the addEventListener(MouseEvent.CLICK, Function); but how run the first picture with out click it ? 

The Solution:
dispatchEvent of course ehehhe. Mr. dispatchEvent simulates the Event like the sample bellow:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var finalClip:Array = [clipOne,clipTwo,clip.....];
 
for ( var gi:uint = 0; gi < e.imagens.length; gi++ )
{
	var smLoader:Loader = new Loader();
	smLoader.load(new URLRequest(e.imagens[gi].thumbs));
 
	finalClip[gi].id = gi;
	finalClip[gi].mouseChildren = false;
	finalClip[gi].buttonMode = true;
	finalClip[gi].addChild(smLoader);
	finalClip[gi].addEventListener(MouseEvent.CLICK, showBigPicture);
}
 
finalClip[0].dispatchEvent(new MouseEvent(MouseEvent.CLICK));

The latest line of code sample do finalClip[0] (first clip of the array) execute the MouseEvent that you have calling showBigPicture function. So easy XD.
Enjoy it.

Leave a Reply