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.
-
function openWebsite(url:String)
-
{
-
getURL(url,'_blank')
-
}
-
website='http://www.flashguru.co.uk'
-
setTimeout(openWebsite,1000,website)
And of course you can use the following syntax aswell:
-
function openWebsite(url:String)
-
{
-
getURL(url,'_blank')
-
}
-
website='http://www.flashguru.co.uk'
-
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:
-
//call the showPopup function once after a second (1000 ms)
-
_global['setTimeout'](this,'showPopup',1000);
Wow, a very nice undocumented feature
Any others I haven’t heard about?
if you use setTimeout in a AS 2.0 class, you can also write it without the bracket : _global.setTimeout(this,’showPopup’, 1000)