Forum Topic: AS: Timeouts

(2,748 views • 17 replies)

This topic is 1 page long.

<< < > >>
None

Inglor

Reply To Post Reply & Quote

Posted at: 9/9/05 11:17 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

AS: Main

This tutorial works in flash 8+

Timeouts are very similar to Intervals and exist in corrosponding languages like JavaScript for just as long.

The main difference is that timeouts only trigger Once after the given ammount of time passes and never again. This is very importent and much needed, and although it can be surpassed with an interval clearning itself, it's much niftier.

First of all let's look at the setTimeout function :

id= setTimeout(functioname:Function, miliseconds:Number, params:Object);

the id is for clearTimeout which I don't know if exists since it's pointless.
The function is the function name to execute when the timeout ends
the miliseconds are the ammount of time the timeout will execute in, for example 2000 miliseconds are 2 seconds.
the params are additional params passed to the function
overall the function is very similar to setInterval and setTimeout in javascript

lets look at this example:

setTimeout(function () {
trace("timed out");
}, 2000);

this would trace "timed out" after 2 seconds, this can be used for all actions needed, and it's good when you want to avoid the frames per second limit.

Ask any questions here
I couldn't find any documentation found , if you did, please share


None

LEMITUDE

Reply To Post Reply & Quote

Posted at: 9/9/05 11:28 AM

LEMITUDE EVIL LEVEL 02

Sign-Up: 08/08/04

Posts: 186

So does timeout work independantly from the FPS? and would it use less CPU than say :

a++;
if (a >= 2000){
do stuff
}

and did you mean that setintervals are better? i couldnt quite understand - sorry for my stupidness.


None

liaaaam

Reply To Post Reply & Quote

Posted at: 9/9/05 11:30 AM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

At 9/9/05 11:17 AM, Inglor wrote:
This tutorial works in flash 8+

That could be useful.. could definitly save time.

I can see a lot of new tutorials coming about Flash 8, the filters and such.. =P


None

T-H

Reply To Post Reply & Quote

Posted at: 9/9/05 11:30 AM

T-H LIGHT LEVEL 39

Sign-Up: 01/07/04

Posts: 4,893

At 9/9/05 11:28 AM, LEMITUDE wrote: a++;
if (a >= 2000){
do stuff
}

LOL that wouldnt time acturately at all sorry, timeout will likely use more cpu but it will actually time properly, what you just suggested is absurd.

Thanks for that Inglor.


None

dELtaluca

Reply To Post Reply & Quote

Posted at: 9/9/05 11:34 AM

dELtaluca LIGHT LEVEL 20

Sign-Up: 04/16/04

Posts: 5,547

didnt even know they existed lol, thx for that

My social worker says im special!

BBS Signature

None

liaaaam

Reply To Post Reply & Quote

Posted at: 9/9/05 11:39 AM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

At 9/9/05 11:34 AM, dELta_Luca wrote: didnt even know they existed lol, thx for that

It doesn't yet =P

Inglor, how about getting a head start and making a flash 8 filters AS? I only know how to use blur and shadow XD Oh and cache as a bitmap, but that is unrelated.


None

Inglor

Reply To Post Reply & Quote

Posted at: 9/9/05 11:41 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

make a AS blurs, you have some version of the 8 filters, don't you? SEPTY and even flash mx 2004 know how to publish flash 8 files, pretty silly...


None

LEMITUDE

Reply To Post Reply & Quote

Posted at: 9/9/05 11:48 AM

LEMITUDE EVIL LEVEL 02

Sign-Up: 08/08/04

Posts: 186

At 9/9/05 11:30 AM, T-H wrote: LOL that wouldnt time acturately at all sorry, timeout will likely use more cpu but it will actually time properly, what you just suggested is absurd.

Yea, but that was my point... sometimes you just want a simple interval in there, without it having to be particularly accurate... so in those occasions its probably best to go with simplicity rather than using a method that consumes more cpu.

But yea, i know it'd be stupid to code something like a "flash clock" using that code, but that wasnt the crux of my original question.


None

Inglor

Reply To Post Reply & Quote

Posted at: 9/9/05 11:50 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

you can change the frames per second with intervals
you can't change intervals with the frames per second

intervals and time outs are also more logic./


None

liaaaam

Reply To Post Reply & Quote

Posted at: 9/18/05 08:12 AM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

This is wierd, setTimeout doesn't appear in blue as other commands do.. nor does it have any documentation at all. It works though, which is the wierdest thing.


None

dELtaluca

Reply To Post Reply & Quote

Posted at: 9/18/05 08:13 AM

dELtaluca LIGHT LEVEL 20

Sign-Up: 04/16/04

Posts: 5,547

At 9/18/05 08:12 AM, -liam- wrote: This is wierd, setTimeout doesn't appear in blue as other commands do.. nor does it have any documentation at all. It works though, which is the wierdest thing.

lool, i know that alot of things that are highlighted dont have documentation but not even being highlighted is a bit strange

My social worker says im special!

BBS Signature

None

JCesta

Reply To Post Reply & Quote

Posted at: 10/4/05 05:58 PM

JCesta LIGHT LEVEL 09

Sign-Up: 07/08/05

Posts: 433

what if i wanted it to just count the time for example at the end of my game it would say how long you played. also it would be helpfull if i could store it as a variable


None

Rhinan

Reply To Post Reply & Quote

Posted at: 5/16/06 05:19 PM

Rhinan EVIL LEVEL 15

Sign-Up: 05/19/05

Posts: 562

so when i have my bullet flying from a gun, how do i have my gun disabled for 2 seconds? Please answer, i'm currently spamming the NG BBS, which isn't working either :P

Thanks for the topic, Inglor

None

genitalwart

Reply To Post Reply & Quote

Posted at: 2/21/09 01:40 AM

genitalwart NEUTRAL LEVEL 03

Sign-Up: 02/06/09

Posts: 68

Thanks!

This is good for HP regenerate.

You can use this, it's pretty much what he posted, lol.

This is just a button, to test it out, but can use the on event clip thingy
on(release)
{

setTimeout(function () {
//this will add 1 point to the variable hp of the frame named hp
++_root.hp
//every 5 sec, duh, lol.
}, 5000);

}

good luck, thanks again author!


None

genitalwart

Reply To Post Reply & Quote

Posted at: 2/21/09 01:52 AM

genitalwart NEUTRAL LEVEL 03

Sign-Up: 02/06/09

Posts: 68

Fuck, nevermind, that doesn't work.


None

Nano256

Reply To Post Reply & Quote

Posted at: 2/21/09 01:55 AM

Nano256 DARK LEVEL 13

Sign-Up: 02/12/05

Posts: 1,474

At 2/21/09 01:52 AM, genitalwart wrote: Fuck, nevermind, that doesn't work.

XD

Nice 3 year bump for nothing.

Move on to ActionScript 3.0 already!
The third post below this one is a lie.

BBS Signature

None

Yambanshee

Reply To Post Reply & Quote

Posted at: 2/21/09 02:39 AM

Yambanshee DARK LEVEL 11

Sign-Up: 10/05/08

Posts: 1,567

At 9/9/05 11:30 AM, T-H wrote:
At 9/9/05 11:28 AM, LEMITUDE wrote: a++;
if (a >= 2000){
do stuff
}
LOL that wouldnt time acturately at all sorry, timeout will likely use more cpu but it will actually time properly, what you just suggested is absurd.

Thanks for that Inglor.

you could do something like this:

var timer:Number = getTimer();
var timeWait:Number = 500; //how long you want the wait to be in miliseconds
if (getTimer()>timer+timewait) {
	timer = getTimer(); //if you want it to wait again
	//do stuff
}

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

None

Nano256

Reply To Post Reply & Quote

Posted at: 2/21/09 02:45 AM

Nano256 DARK LEVEL 13

Sign-Up: 02/12/05

Posts: 1,474

No, what I think he needs is setInterval(), that way it continually replenishes health, as he describes.

Move on to ActionScript 3.0 already!
The third post below this one is a lie.

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 09:40 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!