Copy link to clipboard
Copied
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
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);
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
have your listener call eventlistenerF
Copy link to clipboard
Copied
Sorry. I have told you it is an event but it is just a function. It's my fault. I have a function and I want that after that a new function takes place. Sorry again and thanks
Copy link to clipboard
Copied
what's dispatching the event and what type of event will be dispatched?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
Well they are not events but the first depend on an event thats why I have made the wrong question. I have to say in my own defense that I started with flash long time ago, when it was not Adobe flash. When I started it was AS1, then I jumped to AS2 and I am completely new with AS3 wich is quite diferent. Thanks. I'm going to try this
Find more inspiration, events, and resources on the new Adobe Community
Explore Now