Actionscript, Old Articles - 2 years, 11 months ago - 2 Comments

Flash 8 - setTimeout

Yup, you heard it here first. In Flash 8 actionscript you can tell the player to call a function just once after a specified interval. This means that you dont have to use setInterval anymore to call a function just once. For example the following code calls the openWebsite function after 1 second (1000 milli-seconds) and passes it a url. The openWebsite function then opens that url in a new browser window.

Actionscript:
  1. function openWebsite(url:String)
  2. {
  3. getURL(url,'_blank')
  4. }
  5. website='http://www.flashguru.co.uk'
  6. setTimeout(openWebsite,1000,website)

And of course you can use the following syntax aswell:

Actionscript:
  1. function openWebsite(url:String)
  2. {
  3. getURL(url,'_blank')
  4. }
  5. website='http://www.flashguru.co.uk'
  6. setTimeout(this,'openWebsite',1000,website)

Yet another one of those small features that make our lifes as Flash Developers just that little bit easier :)

Note: That to use the setTimeout function in Actionscript 2 classes, you will need to use array notation to avoid compiler errors as this function was left out of the intrinsic class definition files:

Actionscript:
  1. //call the showPopup function once after a second (1000 ms)
  2. _global['setTimeout'](this,'showPopup',1000);



2 Comments

You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

Nick
Jul 15, 2007 20:01

Wow, a very nice undocumented feature ;) Any others I haven’t heard about?

mark mun
Jan 9, 2008 22:43

if you use setTimeout in a AS 2.0 class, you can also write it without the bracket : _global.setTimeout(this,’showPopup’, 1000)

Note: This is an old article!

Please be aware that the content of this article may no longer be accurate and the links contained within could be broken.

Update Notifications

You can add our RSS feed to your favorite feed reader or recieve an email when a new article is posted by entering your email address below.

    Shu Player allows you to distribute your AIR Applications to users that dont have the AIR Runtime by converting them to standalone applications. Shu Player also adds more commands to do things like open external applications etc...


    If you hate the Adobe Updater like most of us, then just get rid of it.


    Want to quickly find out what version of the Flash Player a client has installed? Send them to www.playerversion.com


    Yet more pv3d goodness. Im loving this funky 3D Flash Lab, the work of Mathieu Badimon. [Update: Apparently this uses Five3D not PaperVision]


    There is an old interview with me on The FWA, its fairly long at 8 pages.


    If you do alot of travelling then it makes sense to get yourself a Priority Pass, which will get you access to over 500 airport lounges worldwide, regardless of whether your flying enconomy, business or first.


    Freelance Switch is a freelancer community with forums, jobs, daily tips and a complete 212 page e-book titled "How to be a rockstar freelancer" for sale.


    Lots of new media jobs at Creative Pool.


    BBC IPlayer is awesome, but its ashame that BBC News is still using Windows Media Player and Real video. Real player is officially badware.


More In Actionscript


More In Adobe Flash


More In Freelancing