So I'm making a simple game but I'm having issues getting my timer to start when I enter a certain frame. I'm using the Frame Enter event listener because that seemed like the best option but the timer automatically starts when the program is executed instead of when it enters the frame I desire.
here's my function
[CODE]var myTimer:Timer = new Timer(1000);
stage.addEventListener(Event.ENTER_FRAME, BeginTimer);
function BeginTimer(myevent:Event):void
{
if (this.currentFrame == 62 && first == true)
{
myTimer.start();
GenerateQuestion();
first = false;
}
}[/CODE]
Whoops, forgot to show where my timer was,
You have to specify the target.
[code]
var myTimer:Timer = new Timer(1000);
stage.addEventListener(Event.ENTER_FRAME, beginTimer);
function beginTimer(myEvent:Event):void
{
if (myEvent.target.currentFrame == 62 && first == true)
{
myTimer.start();
GenerateQuestion();
first = false;
}
}[/code]
It may not give an error, but when you run into a problem like this it is always good to do a trace. You'd get a value of undefined. I believe that the this in your code would reference to the document class, or whatever class that is in.
Sorry, you need to Log In to post a reply to this thread.