Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to allow function to complete if delayed?

Participant ,
Nov 27, 2018 Nov 27, 2018

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

478
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Nov 27, 2018 Nov 27, 2018

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.

Translate
Community Expert ,
Nov 27, 2018 Nov 27, 2018

0 is expected, not 1.

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 27, 2018 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2018 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 27, 2018 Nov 27, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2018 Nov 27, 2018
LATEST

Maybe Workers are what you are looking for.
Worker - Adobe ActionScript® 3 (AS3 ) API Reference

Regards,

JC

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines