header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
Bujji1
Points:160
Posts:0
Answered

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



1
Rayan
Points: 700
Posts:0
Accepted Answer
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
}


2
Bujji1
Points: 160
Posts:0
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

3
Tyson
Points: 680
Posts:0
Accepted Answer
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
Bujji1
Points: 160
Posts:0
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


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 6+1 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions