Subclassing worked for me:
<mx:Script>
<![CDATA[
private var timer:MyTimer;
public function init():void
{
timer = new MyTimer(1000);
timer.bar = "foobar";
timer.addEventListener(TimerEvent.TIMER,
handler);
timer.start();
}
public function handler(event:Event):void
{
trace(MyTimer(event.target).bar);
}
]]>
MyTimer.as:
package
{
import flash.utils.Timer;
public class MyTimer extends Timer
{
private var foo:String = "foo";
public var bar:String = "bar"
public function MyTimer(delay:Number,
repeatCount:int = 0)
{
super(delay, repeatCount);
}
}
}
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Clint Modien
Sent: Tuesday, October 23, 2007 2:30 AM
To: [email protected]
Subject: Re: [flexcoders] passing variables to Timer handler routine
Here was the only workaround...
public static function doSomething(param:Number=0):void {
var t:Timer = new Timer( 300, 1 );
//I can't pass arguments/parameters to my timer method???
var f:Function = function():void{
callTheRealFunc( param);
}
t.addEventListener( TimerEvent.TIMER, f );
t.start();
}
On 10/23/07, Clint Modien <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> wrote:
Looks like this solution is broken.
On 10 Apr 2007 12:29:19 -0700, Gordon Smith < [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote:
You could also subclass Timer and store any additional data you want on
MyTimer.
- Gordon
________________________________
From: [email protected] [mailto:flexcoders@ yahoogroups.com
<http://yahoogroups.com> ] On Behalf Of Erik Price
Sent: Tuesday, April 10, 2007 10:53 AM
To: [email protected]
Subject: Re: [flexcoders] passing variables to Timer handler routine
On 4/10/07, dougco2000 <[EMAIL PROTECTED] <mailto:doug%40dougco.com> >
wrote:
> But since Timer calls a new function, how to best pass along any
> objects or strings that it will need, other than have these as global
> vars?
Excellent question. It's answered here:
http://flexblog.faratasystems.com/?p=125
<http://flexblog.faratasystems.com/?p=125>
e