You have your choice of 

 

1. Storing your state data in the Timer instance. This requires
subclassing Timer because Timer isn't declared to be a 'dynamic' class .

 

2. Storing it in the instance of the class which has the
processSomething() method. Remember that event handler methods, like any
methods, can access all the instance data of the class.

 

The second case makes more sense as a design. You write a processing
class that encapsulates the state of the data that you want to process,
and a Timer to provide the processing heartbeat. You would simply have
code like

 

class Processor

{

    var state:Object;

    var timer:Timer;

 

    function Processor(state:Object):void

    {

        this.state = state;

        timer = new Timer(1000);

        timer.addEventListener(TimerEvent.TIMER, processSomething);

    }

 

    function processSomething(event:TimerEvent):void

    {

        // can access 'state' here

    }

}

 

 

Gordon Smith

Adobe Flex SDK Team

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of markgoldin_2000
Sent: Tuesday, April 22, 2008 10:46 AM
To: [email protected]
Subject: [flexcoders] Re: Add property to an object at run time

 

I probably could while I haven't done that yet.
The reason I was asking this question is:
Let's say I want to a Timer:
timer:Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, processSomething);
private function processSomething(event:TimerEvent):void 
{
// do some processing
}
In order to let processSomething access anything from the process 
that creates Timer in a first place I have to create a bunch or 
vars. "visible" in processSomething function. While technically it 
should work but still I would prefer dealing with properties and 
parameters and not with vars. I was thinking to add some props. to 
Timer and doing event.target.newPropName to acceess them.

--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> You can use a Dictionary to associate data with the Timer.
> 
> 
> 
> ________________________________
> 
> From: [email protected] <mailto:flexcoders%40yahoogroups.com>

[mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of Tracy Spratt
> Sent: Tuesday, April 22, 2008 10:09 AM
> To: [email protected] <mailto:flexcoders%40yahoogroups.com> 
> Subject: RE: [flexcoders] Add property to an object at run time
> 
> 
> 
> Most clases in AS3 do not allow this.
> 
> Tracy
> 
> 
> 
> ________________________________
> 
> From: [email protected] <mailto:flexcoders%40yahoogroups.com>

[mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of markgoldin_2000
> Sent: Tuesday, April 22, 2008 10:52 AM
> To: [email protected] <mailto:flexcoders%40yahoogroups.com> 
> Subject: [flexcoders] Add property to an object at run time
> 
> 
> 
> Can a property be added to a Flex object (Timer) at the run time?
> 
> Thanks
>

 

Reply via email to