Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6777059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:06:10+00:00 2026-05-26T16:06:10+00:00

Is there any way to implement waiting for, say, 3 seconds in ActionScript, but

  • 0

Is there any way to implement waiting for, say, 3 seconds in ActionScript, but to stay within same function? I have looked setInterval, setTimeOut and similar functions, but what I really need is this:

public function foo(param1, param2, param3) {
  //do something here
  //wait for 3 seconds
  //3 seconds have passed, now do something more
}

In case you wonder why I need this – it is a legal requirement, and no, I can’t change it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:06:11+00:00Added an answer on May 26, 2026 at 4:06 pm

    Use the Timer to call a function after 3 seconds.

    var timer:Timer = new Timer(3000);
    timer.addEventListener(TimerEvent.TIMER, callback); // will call callback()
    timer.start();
    

    To do this properly, you should create the timer as an instance variable so you can remove the listener and the timer instance when the function is called, to avoid leaks.

    class Test {
        private var timer:Timer = new Timer(3000);
    
        public function foo(param1:int, param2:int, param3:int):void {
            // do something here
            timer.addEventListener(TimerEvent.TIMER, fooPartTwo);
            timer.start();
        }
    
        private function fooPartTwo(event:TimerEvent):void {
            timer.removeEventListener(TimerEvent.TIMER, fooPartTwo);
            timer = null;
            // 3 seconds have passed, now do something more
        }
    }
    

    You could also use another function inside your foo function and retain scope, so you don’t need to pass variables around.

    function foo(param1:int, param2:int, param3:int):void {
        var x:int = 2; // you can use variables as you would normally
    
        // do something here
    
        var timer:Timer = new Timer(3000);
        var afterWaiting:Function = function(event:TimerEvent):void {
           timer.removeEventListener(TimerEvent.TIMER, afterWaiting);
           timer = null;
    
           // 3 seconds have passed, now do something more
    
           // the scope is retained and you can still refer to the variables you
           // used earlier
           x += 2;
        }
    
        timer.addEventListener(TimerEvent.TIMER, afterWaiting);
        timer.start();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to implement a URL mechanisim in asp.net like it has
is there any way to implement timeout option for individual tests in a bunch
Is there any way to implement pop-ups similar to the system ones on iPhone?
Is there any way to implement something similar to Chatroulette without using Flash or
Is there any tricky way to implement a set data structure (a collection of
Is there any other way in java to implement call backs apart from inner
Is there any non-hacky way to determine wether a class' superclass implements a particular
Is there any way to check whether a file is locked without using a
Is there any way to capture the MouseDown even from the .NET 2.0 TextBox
I was wondering if there is any way to tune (on a linux system),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.