Thanks for the response ..
This is the code that I have ( it works ) but is it the right way
to do it :) ..
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="init()"
width="100%" height="100%" xmlns:ns1="*">
<mx:Script>
<![CDATA[
import flash.utils.Timer;
import flash.events.Event;
private var cnt:int=0;
public var tm:Timer = new Timer(1000,0);
private function init():void
{
tm.addEventListener(TimerEvent.TIMER,fired);
tm.start();
}
public function fired(Timer:TimerEvent):void
{
dispatchEvent(Timer);
t.text = (++cnt).toString();
}
]]>
</mx:Script>
<mx:Text id="t" text="here"/>
<ns1:myPanel x="145" y="95">
</ns1:myPanel>
</mx:Application>
and then the myPanel.mxml source
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="init()" width="100" height="100">
<mx:Script>
<![CDATA[
import mx.core.Application;
import flash.events.TimerEvent;
private var cnt:int=0;
private function init():void
{
Application.application.addEventListener(TimerEvent.TIMER,fired);
}
private function fired(e:TimerEvent):void
{
t2.text = "myPanel "+(++cnt).toString();
}
]]>
</mx:Script>
<mx:Text id="t2" text="here"/>
</mx:Canvas>
--- In [email protected], "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
>
> If an event "bubbles" you can listen for it in any ancestor, like
> Application.application.
>
>
>
> Look at the docs for the timer event, to se if if bubbles. If it does
> not, in the timer component, re-dispatch an event, setting the second
> argument to true, to make it bubble.
>
>
>
> Tracy
>
>
>
> ________________________________
>
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of iilsley
> Sent: Tuesday, March 27, 2007 11:50 PM
> To: [email protected]
> Subject: [flexcoders] newbie question: Timer across components..
>
>
>
>
> Is it possible to have a Timer in one component and have another
> component
> execute a function when that timer fires ?
>
> eg:
>
> Comp1 has a timer set for 3 seconds ..
>
> In Comp2 I want to 'capture' the TimerEvent.TIMER from Comp1 to execute
> a function defined in Comp2..
>
> ---
> I currently have something working but I kinda feel its just not the
> right way .. :) ..
>
> In Comp2 I have
>
> Application.application.ti.addEventListener(TimerEvent.TIMER,fired);
>
> where 'ti' is the Timer .
>
> Is there a better way to listen for the event ?
>
>
> Thanks
>