hi! im working on this project that would display the level message “level n” on the screen for a few seconds. im using a timer and it worked in the internal script but when i transferred it to an external script the addEventListener function isnt working.
here’s my code:
package Game{
import flash.events.*;
import flash.utils.*;
public class timerClass{
public var count:Timer = new Timer(2000,1);
public var timerFinished:Boolean;
public function timerClass(){
addEventListener(Event.ENTER_FRAME, startTimer);
}
public function startTimer(evt:Event){
count.addEventListener(TimerEvent.TIMER, timerStart);
count.start();
count.addEventListener(TimerEvent.TIMER_COMPLETE, onFinish);
if(timerFinished){
evt.target.parent.gotoAndStop(2);
}
}
function timerStart(evt:TimerEvent):void{
trace("timer started");
timerFinished = false;
}
function onFinish(evt:TimerEvent):void{
timerFinished = true;
trace("done!!!");
count.removeEventListener(TimerEvent.TIMER_COMPLETE, onFinish);
}
}
}
the first code would give a 1080 error but if add a “this” or “root” to the addEventListener,this.addEventListener(Event.EnterFrame, startTimer), function it gives a 1061 error.
i also tried using it without the eventListener
public class timerClass{
public var count:Timer = new Timer(2000,1);
public var timerFinished:Boolean;
public function timerClass(){
//addEventListener(Event.ENTER_FRAME, startTimer);
}
public function startTimer(){
count.addEventListener(TimerEvent.TIMER, timerStart);
count.start();
count.addEventListener(TimerEvent.TIMER_COMPLETE, onFinish);
if(timerFinished){
}
}
function timerStart(evt:TimerEvent):void{
trace("timer started");
timerFinished = false;
}
function onFinish(evt:TimerEvent):void{
timerFinished = true;
trace("done!!!");
evt.target.parent.gotoAndStop(2);
count.removeEventListener(TimerEvent.TIMER_COMPLETE, onFinish);
}
}
}
it works! but after the timer has completed and when it is supposed to go to the next frame to start the game… this is fired by the output window
ReferenceError: Error #1069: Property parent not found on flash.utils.Timer and there is no default value.
at Game::timerClass/onFinish()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.utils::Timer/tick()
i would really need your help on this one. ive been stuck because of this dilemma for a while now.
thanks and may God bless you!!!