A wait in action script

is there a command that is in a action script which for x amount seconds the code is paused?

lets say i have a button with this code


on (release) {
    // this is done instantly
    // WAIT 5 seconds
    // this is done five seconds afterwards
}

Possible? if so how??

have a look at setInterval()

Um i searched abit on google and flash 5 help for that now but couldnt find alot, are you sure it works on flash 5?

Yeah your rite about it not being suported in Flash 5:

Availability: ActionScript 1.0; Flash Player 6

I guess you could just use a getTimer, bit of a dirty way to do but it would work i guess.

[AS]on(release){
//WHAT YOU WANT TO STRAIGHT AWAY
time = getTimer()
trace(“start”)

this.onEnterFrame = function(){
	curTime = getTimer()
	dif = curTime - time
	//trace(dif)
	if(dif > 5000){
		trace("5seconds")
		delete this.onEnterFrame
		//WHAT YOU WANT IT TO DO AFTER 5 SECONDS
	}
}

}[/AS]

But I have a feeling this.onEnterFrame wont work cause its flash 5. So im stumped.

Oh sorry about that, I didn’t realize it wasn’t available in Flash 5 :frowning:

That new event model (dynamic event handlers) are available since version mx only. You would have to use something like onClipEvent and getTimer instead to count the time.

Open a new window with the swf, when you want it to pause, close the window, and start timing with javascript, then reopen the window with a spercial argument after the time’s elapsed. :lol:

um nokrev i dont get that and i dont think it will work the way i want it to…

aussie devil, do you know how to do the get timer then for flash 5?
:d:

Edit:
and hey,


some_xes = a_number*"X";

How can i get this to work so that if a_number is 5 then some_exes is XXXXX and if a_number is 0 then we have zero Xes, IE, it multiplies a text a with a number.

OK lets say i do it in flash MX, how can it be simply done…

as if its easier i will use mx instead.

That’s why it was wrapped in sarcasm tags… :wink:

That new event model (dynamic event handlers) are available since version mx only. You would have to use something like onClipEvent and getTimer instead to count the time.

onClipEvent and enterFrame events don’t work on button objects in any version of Flash.

using for loop


some_xes="";
for(i=0;i<a_number;i++)
{
some_xes+="X";
}
trace(some_xes);//this'll give you a string with a_number (number) of "X"

If you use MX, somtin like this will work: [AS]on(release){
trace(“START CODE”)

codeInt = setInterval(delayFunc,5000)

function delayFunc(){
	
	trace("DELAYED CODE")
	clearInterval(codeInt)
}

}[/AS]

Hmm… v5, ay?

Create a blank movie clip on the stage and call it ‘timer1’. Inside this clip, put a ‘stop();’ on the first frame, then skip forward 5 seconds (5 x your framerate), and insert a keyframe with the actions to execute after 5 secs. Then, on your button put:

on (release) {
//thing to do instantly
_root.timer1.play();
}

That’s the nice, messy AS-noob’s way :stuck_out_tongue: (for people like me)

[quote=johpoke]um nokrev i dont get that and i dont think it will work the way i want it to…

aussie devil, do you know how to do the get timer then for flash 5?
:d:

if you relly wanted to use getTimer() in flash 5 you could do it like this