views:

43

answers:

2

I am trying to to attach a function with parameters to the timer but it says "unrelated type function" is there any way to get around this??

code example:

var redoTimer:Timer = new Timer(50);

redoTimer.addEventListener(TimerEvent.TIMER, saySomething("helloo"));
redoTimer.start();

this wont seem to work but is there a way to pass on arguments???

thanks Matthy

+3  A: 

You can't really do that, the closest equivalent would be using a small inline function to wrap your own function:

var redoTimer:Timer = new Timer(50);

redoTimer.addEventListener(TimerEvent.TIMER, function(e:Event):void { saySomething("helloo") } );
redoTimer.start();
grapefrukt
+3  A: 

The second parameter to the addEventListener function should be a function. Your code actually executes the method saySomething("helloo") and tries to use its return value as the second parameter to the addEventListener and hence the error.

Also, the event listener function should accept one and only one argument of type flash.events.Event. They can have optional arguments with default values if you want to call them explicitly from your code though.

Amarghosh