setTimeout in Flash 7

I’ve written a class that let you easily do a setTimeout in flash 7
http://blog.guya.net/?p=5

I’m only starting to release some code to the public and would really appreciate some feedback about it.
do you found it useful, easy to understand, etc ?

My only feedback would be that it seems a little “out of the way” to make this class to simulate setTimeout. Ideally, you’d just write your own setTimeout global function. This would not only be simpler, but easier for others to use (knowing its interface) and be more helpful in maintaining backwards compatibility

Thanx for your feedback senocular. :slight_smile:

The functions are static which make it similar in use to a public function. import the class, and call anywere you like Timeout.set(func, interval);
I tried to make the Timeout.set interface similar to the original flash 8 setTimeout I evan made the function pseudo overloaded, you can send an object reference but you don’t have to.

setTimeout(func, interval, variable1, variable1,… variableN);
Timeout.set(func, interval, variable1, variable1,… variableN);

setTimeout(obj, “func”, interval, variable1, variable1,… variableN);
Timeout.set(obj, func, interval, variable1, variable1,… variableN);

I now noticed that in the original setTimeout, when you reference an object you send the function name as a string (opss). Still, it’s pretty similar :slight_smile:

Anyhow, I found it easy to use (maybe I’m biased :)) it’s in my classpath and ready to fire whenever it’s needed. Mainly for testing though, I do alot of fscommand to javascript which is asynchronic and somtime you need somthing to happen in a few ms latter and you don’t want to start messing with clearing these intervals.

I see your point about putting this in a class is maybe more then what this simple functionality deserve. I intentionally kept a simpler version of the function inside the class called Timeout.sets (the last ‘s’ stands for simple) it does the same but without the overloading bs. One can easily copy this function and do whatever he wants with it. It is also easier to understand how the function is working with the arguments list and the Function.apply() method.

If we make a global function named setTimeout Wouldn’t it conflict with the built in one, once we try to upgrade it to flash 8?

Once you have Flash 8, you won’t need to make a global setTimeout function since one already exists. And if you did, it would just overwrite the existing one.

I have to agree with senocular only because if you were to take it out of the class and remove the data types you could also use this in Flash 6. Although the class adds portability so you could do something along these lines:

import net.guya.Timeout;
_global.setTimeout = Timeout.set;
_global.clearTimeout = Timout.clear;

Other than that great work - simple yet extremely useful :thumb:

I have to agree with you guys :slight_smile:
I thought one could easily look inside the .as and make her own function out of of it. This was a mistake, users want to copy -> past -> run. they don’t want to be bothered with altering code inside classes. and thats how it suppose to be, especially with a simple functionality like this.

Here is my last take on this function:

**setTimeout for flash 6 and above - **copy and paste it in your flash 6 files

*_global.setTimeout = function (o, func, ms){*
*var a = new Array();*
* for(var i = 3; i < arguments.length; i++) a.push(arguments*);*
*var n = setInterval(function(){func.apply(o, a); clearInterval(n);}, ms)*
*return n;*
*}*

and use it like this:

*setTimeout(this, trace, 1000 , “string to trace”);*

Thanks for your feedback :slight_smile: