Skip to main content
MamenFLASH$
Known Participant
June 1, 2016
Answered

How to delay an event?

  • June 1, 2016
  • 1 reply
  • 2427 views

Hi everybody. I want to delay an event some minutes or seconds in order not to interfere with another event. How can I dow it? Thanks in advance.

Regards

This topic has been closed for replies.
Correct answer kglad

Thanks for all your patience. Well I have a movieClip that appears throw code (addChild....) and as this hapens I have a sound taken from the library. The other thing that hapens next is another Clip with another sound. That's why I want to display first one and then the other in order not to mix both sounds.


then you're NOT trying to delay an event being dispatched.

you can just use the timer to delay the call to a function that does something with '..another Clip with another sound'.

var t:Timer=new Timer(5000,1);

t.addEventListener(TimerEvent.TIMER,f2);

function f1():void{

addChild(mc1);

t.start();

}

function f2(e:TimerEvent):void{

addChild(mc2);

}

1 reply

kglad
Community Expert
June 1, 2016

there are several ways to handle that.

one would be to use a listener and listener function to capture the event, remove the listener, use a timer and timer listener to capture a delayed timerevent in the timer listener function where you re-dispatch the original event.

MamenFLASH$
Known Participant
June 1, 2016

Wel I think it will be perfect with a timer. I have tried to put a timer and then with an "if"sentence asking if the timer has a determined value then do the other hings I want to, but obviously my code is wrong because it doesnt work. So how can I do it? Thanks

MamenFLASH$
Known Participant
June 1, 2016

var capturedE:Event;

var delayTime = 5000;

var t:Timer=new Timer(delayTime,1);

t.addEventListener(TimerEvent.delayDispatchF);

function eventlistenerF(e:Event):void{

// remove the listener that calls this

capturedE=e;

t.start();

}

function delayDispatchF(e:TimerEvent):void{

capturedE.currentTarget.dispatchEvent(capturedE);

}


Ok. I'm a bit confused. So this piece of code manages the time, but how can I conect this with both events? I mean the event just executed and the new one that I want to delay. Thanks