Skip to main content
PATurmel12
Inspiring
November 27, 2018
Answered

How to allow function to complete if delayed?

  • November 27, 2018
  • 1 reply
  • 549 views

If I want a function with a delay, such as a timer or a Loader, to complete before continuing after delay.

For example:

var i:int = new int();

var tim:Timer = new Timer(1000);

tim.addEventListener(TimerEvent.TIMER, goTim);

thisfun();

trace(i);

function thisfun():int{

tim.start();

return (i);

}  //  function thisfun

function goTim(event:TimerEvent):void{

i = i+1;

}

//  returns 0 instead of 1

This topic has been closed for replies.
Correct answer PATurmel12

you appear to know how to use a timer to delay code execution so it's not clear why you're asking how to delay code execution.


I was looking for something simpler such as 'break' or 'continue'.

The code I'm working with is a bit extensive, it will take some work to write a workaround.

1 reply

kglad
Community Expert
Community Expert
November 27, 2018

0 is expected, not 1.

what are you trying to do or what are you confused about?

PATurmel12
Inspiring
November 27, 2018

I want a delay before continuing to 'return', but I take it that's not possible with AS3 since it is single threaded.

I think I'll have to write some sort of workaround such as using setInterval and checking for conditions.

kglad
Community Expert
Community Expert
November 27, 2018

you appear to know how to use a timer to delay code execution so it's not clear why you're asking how to delay code execution.