View Full Version : TimerEvent
tom12
07-02-2009, 11:40 AM
Hello,
I'm using the following code to delay my movie a set time for each frame:
stop();
var myTimer: Timer = new Timer(8000);
myTimer.addEventListener(TimerEvent.TIMER, timerF);
myTimer.start();
function timerF(e:TimerEvent):void {
nextFrame();
}
This works fine but I want to be able to change the length of the delay for each frame. I've tried alsorts but my as3 knowledge is limited so any help would be greatly appreciated.
Thanks
ExNihilio
07-02-2009, 11:55 AM
so basically u want to change the delay for each frame.. Use that;
function timerF(e:TimerEvent):void {
nextFrame();
myTimer.removeEventListener(TimerEvent.TIMER, timerF);//remove the listener
}
function nextFrame(){
myTimer.delay=6000;//this is where u set the new delay..
myTimer.addEventListener(TimerEvent.TIMER, timerF);//add the listener
myTimer.start();//start the timer
}
tom12
07-02-2009, 02:40 PM
Thanks for your help but can you tell me how I apply this? I've got my code on the first frame and your code in the second frame but it's throwing up errors.
Cheers
ExNihilio
07-03-2009, 06:50 AM
put it on the first frame if your whole code or these functions are in the first frame..
And add to your nextFrame function the things i wrote in my nextFrame function..Change the timer listener like i wrote.. And if u want the delay attribute to be changeable, u mst use some variable. Like put the delay times in an array, and use it to set the delay..
tom12
07-03-2009, 08:09 AM
Thanks again for your help but please can you help me some more...
So in the first frame I have:
function timerF(e:TimerEvent):void {
nextFrame();
myTimer.removeEventListener(TimerEvent.TIMER, timerF);//remove the listener
}
function nextFrame(){
myTimer.delay=6000;//this is where u set the new delay..
myTimer.addEventListener(TimerEvent.TIMER, timerF);//add the listener
myTimer.start();//start the timer
}
and then in the other frames when I want to change the delay I have:
function nextFrame(){
myTimer.delay=6000;//this is where u set the new delay..
myTimer.addEventListener(TimerEvent.TIMER, timerF);//add the listener
myTimer.start();//start the timer
}
but when I do this I'm getting errors of "overriding a function that is not marked for override" on the first frame and "duplicate function definition" in the frames that I use the 2nd bit of script. Please could you give me a more specific example?
Thanks again
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.