MTALY
MTALY

Reputation: 1772

Actionscript3 setting time delay

trying to make a time delay before redirection to a specific web page , I got many errors during the compiling process , sorry new to actionscript :

package  
{
    import flash.display.*;
    import flash.net.*;
    import flash.system.*;
    import flash.utils.*;
    import flash.events.*;





    public class test extends flash.display.Sprite
    {


        public function test()
        {

            super();
            flash.net.navigateToURL(new flash.net.URLRequest("http://youpassed-theexam.com/congrats"), "_self");
            return;

        }


    }


 setInterval(test,5000);


}

Upvotes: 1

Views: 63

Answers (1)

Gurtej Singh
Gurtej Singh

Reputation: 3234

A couple of issues with your code:

  1. Constructors of classes are immediately called once the class is instantiated. You should create a separate method and call that with a delay from within your constructor.

  2. setInterval would fire repeatedly after every set interval. You should rather use setTimeout.

  3. Classes should have a Sentence caps naming convention, so Test and not test. Just a best practice. Nothing wrong syntactically.
  4. Constructors do not return anything so we do not need the return statement.
  5. Once you have imported a class, you do not need to write the full name of the class to access it's methods.
  6. Try to avoid * based import statements. It does tend to import a lot more classes than just the required class. Again, just a best practice.

So your code should look something like this below:

package  
{
    import flash.display.Sprite;
    import flash.net.URLRequest;
    import flash.net.navigateToURL;
    import flash.utils.setInterval;
    import flash.utils.setTimeout;

    public class Test extends flash.display.Sprite
    {
        public function Test()
        {
            super();
            setTimeout(gotoURL, 5000);
        }

        protected function gotoURL():void
        {
            navigateToURL(new URLRequest("http://youpassed-theexam.com/congrats"), "_self");
        }
    }
}

Hope this helps. Cheers.

Upvotes: 3

Related Questions