Be a Supporter!

AS: Timeouts

  • 3,547 Views
  • 17 Replies
New Topic Respond to this Topic
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
AS: Timeouts 2005-09-09 11:17:55 Reply

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

LEMITUDE
LEMITUDE
  • Member since: Aug. 8, 2004
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to AS: Timeouts 2005-09-09 11:28:12 Reply

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.

liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Timeouts 2005-09-09 11:30:01 Reply

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


Sup, bitches :)

BBS Signature
T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS: Timeouts 2005-09-09 11:30:51 Reply

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.

dELtaluca
dELtaluca
  • Member since: Apr. 16, 2004
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS: Timeouts 2005-09-09 11:34:50 Reply

didnt even know they existed lol, thx for that


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature
liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Timeouts 2005-09-09 11:39:19 Reply

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.


Sup, bitches :)

BBS Signature
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Timeouts 2005-09-09 11:41:26 Reply

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...

LEMITUDE
LEMITUDE
  • Member since: Aug. 8, 2004
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to AS: Timeouts 2005-09-09 11:48:10 Reply

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.

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Timeouts 2005-09-09 11:50:24 Reply

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./

liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Timeouts 2005-09-18 08:12:33 Reply

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.


Sup, bitches :)

BBS Signature
dELtaluca
dELtaluca
  • Member since: Apr. 16, 2004
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS: Timeouts 2005-09-18 08:13:43 Reply

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


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature
JCesta
JCesta
  • Member since: Jul. 8, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: Timeouts 2005-10-04 17:58:14 Reply

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

Rhinan
Rhinan
  • Member since: May. 19, 2005
  • Offline.
Forum Stats
Member
Level 15
Game Developer
Response to AS: Timeouts 2006-05-16 17:19:50 Reply

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
genitalwart
genitalwart
  • Member since: Feb. 6, 2009
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: Timeouts 2009-02-21 01:40:03 Reply

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!

genitalwart
genitalwart
  • Member since: Feb. 6, 2009
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: Timeouts 2009-02-21 01:52:36 Reply

Fuck, nevermind, that doesn't work.

Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to AS: Timeouts 2009-02-21 01:55:17 Reply

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

XD

Nice 3 year bump for nothing.


#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature
Yambanshee
Yambanshee
  • Member since: Oct. 5, 2008
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: Timeouts 2009-02-21 02:39:00 Reply

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
Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to AS: Timeouts 2009-02-21 02:45:06 Reply

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


#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature