Subscribe to RSS
get email updates
home | about | pixDif AIR app | video tutorials
polyGeek.com

place your ad here

Web Premium



Get Qwest High Speed Internet



Wait just a second

November 2nd, 2006 . by polyGeek

How many times have you been coding Actionscript and needed to run some code in a second, or two, or whatever? I know, you can create a setInterval, blah, blah, blah. But that’s such a pain in the the ass.

So, I made a class with just one method to do make it easier for you to wait a second. If you need to call a function/method in, say half-a-second, then all you would write is this:

Wait.For(500, myMethod).

Done.

But, wait, there’s more. You can pass arguments that you need to send to your function/method. Just like this:

Wait.For(500, myMethod, “coffee”, “hot”, “cream”, suger”);

is that sweet or what?

There is a limit of 10 arguments that you can pass. If you really need to send more then edit the class yourself.

Here’s the code for the class below or you can download the file: Wait.asWait.zip.

If something here has proved valuable to you then feel free to drop a couple of bucks in the tip-jar.

Post to Twitter Post to Delicious Post to Facebook Post to Reddit Post to StumbleUpon


similar posts

10 Responses to “Wait just a second”


comment number 1 by: Sergi Mansilla

There is an undocumented function in Flash that does that: setTimeout. It works very similar to setInterval.
You can find out how to use it at http://www.flashguru.co.uk/flash-8-settimeout/

By the way, you should use dynamic arguments. The way you send arguments to the callback function is not very elegant, and it limits the amount of arguments to send. Take a look to this:
http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary369.html

Cheers

comment number 2 by: Rasmus

Or you could use:
callback(a.slice(2, a.length));

to pass as many arguments as needed

comment number 3 by: polyGeek

@Rasmus, true enough. Good thanking.

comment number 4 by: Andy

Flash already has this:

setTimeout(scope, “function”, milliseconds, param1, param2, etc);

comment number 5 by: polyGeek

@Andy, you sure that isn’t a custom class you wrote? setTimeout isn’t in the help files and the following code doesn’t do anything:

setTimeout(this, CB, 100, “hi”);

function CB(arg:String):Void {
trace(arg);
}

comment number 6 by: Rasmus

setTimeout is an undocumented function introduced in Flash 8. For more info see this post from Flashguru: http://www.flashguru.co.uk/flash-8-settimeout/

comment number 7 by: polyGeek

@Rasmus, wonderful, thanks for pointing this out. The problem with the code above is that here is no ‘scope’ parameter. So this works as expected.

setTimeout(CB, 1000, “hi”);

function CB(s:String):Void {
trace(s);
}

comment number 8 by: wolfito

did you try _global.setTimeout(CB, 1000, “hi”); ?

i use that when i need a method call to wait

:)

comment number 9 by: wolfito

sorry i forgot the scope:

(inside a class)

timerInterval = _global.setTimeout(this, “functionName”, 100);

comment number 10 by: polyGeek

@wolfito, you know, I’ve never really used _global before. I think static classes do the same thing for me.

By the way, wicked cool sight you have. I can’t read it but I love the detail you put into it. Something as simple as making the text coast to a stop when scrolling is a very sweet effect and looks quite professional. Kudos.

   Welcome back (Change)

Leave a Reply

comment feed RSS   subscribe to this comment thread

Recent Posts

   



polyGeek.com

© Copyright 2008 polyGeek.com / Dan Florio, All Rights Reserved Except Where Explicitly Stated
Web Developement Blogs - Blog Catalog Blog Directory
M2 Websites
Local Directory for Los Angeles, CA

Better Tag Cloud