4/29/2010 6:30:16 AM
Title:
TimerEvent
I have the following code
writerTimer = new Timer(500);
writerTimer.start();
writerTimer.addEventListener(TimerEvent.TIMER, timerHandler);
And that is calling the timerHandler function and which is taking TimerEvent event object as parameter. May be a silly question, this event object is getting generated for every 10 Milliseconds. Is there any way to avoid passing TimerEvent as a parameter. I am not any way not using it in the function. Because in action script addEventListener function must take the object as a parameter and I am not able create it as an mxml components
Regards
Bujji
Rayan
Points: 700
Posts:0
4/29/2010 6:50:29 AM
For such cases I use some intermediate function which takes the event and calls the normal function :
writerTimer = new Timer(500);
writerTimer.start();
writerTimer.addEventListener(TimerEvent.TIMER, myIntermediateFunction);
private function myIntermediateFunction(evt:Event):void{
// call the timer handler function without passing event object
timerHandler();
}
private function timerHandler():void{
//your code
}
4/29/2010 7:18:54 AM
Thanks Rayan
I tried it . But still in profiling i see the number of objects for Events are increasing But this is much much better than what I had earlier .
Regards
Bujji
Tyson
Points: 680
Posts:0
4/29/2010 7:59:57 AM
I think you are worried about the event Object for performance. To make it more clear I would like to tell you that , as soon as you attach an event listener , The event Object is created and whether you use it or not its there inside to use for flash player classes. In MXML whether you use it or not its still generated internally. The only thing is that when event Object is passed , we are able to get its reference and the profiler will show that. It does not pose any danger to performance. The object is too small and not generated new every time. Just values are updated so does not consume more memory if called every 10 seconds. I hope its clear.
4/29/2010 8:31:34 AM
Thanks Tyson for the clarification .I want to accept both as an answers , but not able to .
Once again thanks