views:

56

answers:

2

I am using a timer function in Flex

but it gives me a run time error.

my code looks like this:

import flash.utils.Timer;
public function fnname():void
{
   if(x==150)
    {
     while (y==0)
     {  x ++;
        Timer(100);
     }
    }
}

the error i get is: Error #1034: Type Coercion failed: cannot convert 100 to flash.utils.Timer.

+1  A: 

ClassName(value) is the syntax for data coercion (converting strings to integers and such). Try:

new Timer(100);

Also make sure you are actually attaching callbacks to the Timer. Simply instantiating a timer doesn't work like a 'pause' or 'delay' function.

audiodude
+1  A: 

This is not how you use a Timer - it is not possible to make the execution stop in this way.

The actual error tells you that you cannot cast 100 to an object of type Timer, that is because what you have written is actually a cast. If you want to create the object do

new Timer(100);

(so you forgot the new)

An example on how to use the Timer class.

Simon Groenewolt