Skip to main content
June 10, 2008
Answered

can't get the timer to work

  • June 10, 2008
  • 5 replies
  • 493 views
hello,

I'm new to AS 3. However, I'm finding it to be baffling overall. Every time I try to go deeper with it I find I can't get what appear to be simple tasks to function.

This time I'm trying to work with the timer class. I have two layers: display and actions. In the display layer (which is below the actions layer), I've got a single instance of dynamic text. I gave it an instance name of dtDisplay.

In the actions layer, I have a keyframe and this code:

import flash.utils.Timer;

function runMany(event:TimerEvent):void {
trace("runMany() called @ " + getTimer() + " ms");
}

var myTimer:Timer = new Timer(25000,1);
myTimer.addEventListener(TimerEvent.Timer, runMany);
myTimer.start();


dtDisplay.text = 'haha';


What I'm trying to achieve with this code is a 25 second delay, then the dynamic text being applied to the control.

However, when I run this flash file, I get an error on the line with myTimer.addEventListener:

"1119: Access of possibly undefined property Timer through a reference with static type Class."

Now, I think this could be related to my class path. I've set the class path to have two values:

c:\program files\Adobe\Adobe Flash CS3\en\Configuration\ActionScript 3.0\Classes
C:\Program Files\Adobe\Adobe Flash CS3\en\First Run\Classes\mx\utils

The second path has at least the 'utils' part of the import statement at the top of my frame. However, when i peruse the utils.as, i see no reference to a timer class.

I have searched my hard drive for AS files that contain the timer class but don't see it.

Does anyone have any ideas? Thanks.
This topic has been closed for replies.
Correct answer J_Rocker
Hey!
instead of myTimer.addEventListener(TimerEvent.Timer, runMany);

myTimer.addEventListener("timer", runMany);

What that error dialog was telling you was that there is no Timer property of TimerEvent.
(there is TimerEvent.TIMER though, i don't know what it does (i'm new too) AS3 is very particular about things like that)

if your function parameter (event:TimerEvent) disagrees, try (event:Event) or (e:Event)

5 replies

Inspiring
June 11, 2008
Haha. Glad i could help!
June 11, 2008
hey,

i just added a second keyframe for the actions layer and put a stop() in it. that stopped the flashing.

(please disregard that part of the last post.)
June 10, 2008
thanks, gratch.

Mr Rocker, you rock. I appreciate your response. you helped me get to the point where it runs.

however, it doesn't delay quite like i expect. My code looks like this:


import flash.utils.Timer;

function runMany(event:Event):void {
trace("runMany() called @ " + getTimer() + " ms");
}

var myTimer:Timer = new Timer(100000,1);
myTimer.addEventListener(TimerEvent.TIMER, runMany);
myTimer.start();

dtDisplay.text = 'haha';


...and, it doesn't delay 100 seconds before refreshing my text control. For some reason, it is constantly refreshing it.

Also, i don't see how we're releasing the object from memory doing this. if we're not, it is useless as timer code that is reused often.

thanks for the help.
J_RockerCorrect answer
Inspiring
June 10, 2008
Hey!
instead of myTimer.addEventListener(TimerEvent.Timer, runMany);

myTimer.addEventListener("timer", runMany);

What that error dialog was telling you was that there is no Timer property of TimerEvent.
(there is TimerEvent.TIMER though, i don't know what it does (i'm new too) AS3 is very particular about things like that)

if your function parameter (event:TimerEvent) disagrees, try (event:Event) or (e:Event)
June 10, 2008
I'm new to AS3 also but I think You need to add this
import flash.events.TimerEvent;
with your code as you are calling a event with the timer in "function runMany(event:TimerEvent):void "
hope this may help