Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-15-2012, 03:06 PM   #1
lex1
Registered User
 
Join Date: Nov 2004
Posts: 5
Default Frame Delay "Random" Timer

I been using this code forever and works when I want a specific frame delay

Code:
stop(); 
var pause:Number = setInterval(moveAlong, 3600); 
function moveAlong():Void { 
    clearInterval(pause); 
    play(); 
}
How can this code be modified to specify random delay
from a minimal value (ie 3 seconds)
to a maximum value (ie 6 seconds)

Thanks

PS. I have searched the forums and library and most are for loading MCs and others look over complicated for a frame delay situation.
lex1 is offline   Reply With Quote
Old 04-15-2012, 05:53 PM   #2
mandog
Registered User
 
Join Date: Apr 2012
Posts: 7
Default

Its a bit more complicated with AS2 I would try converting to AS3 for this trust me.
mandog is offline   Reply With Quote
Old 04-15-2012, 06:22 PM   #3
neilmmm
Senior Member
 
neilmmm's Avatar
 
Join Date: Oct 2005
Location: dorset
Posts: 1,637
Default

you just make the delay a number variable

put an mc on the stage and call it toggleDelay_mc and put this code on a frame

may i also suggest you use setTimeout instead of setInterval - it works like setInterval but setTimeout is only called once and does not therefore have to be cleared

Code:
var threeSecDelay:Boolean = false;
var delay:Number;
function moveAlong():Void {
	//play();
	trace("delay = "+delay);
}
toggleDelay_mc.onRelease = function() {
	trace("pressed");
	threeSecDelay = !threeSecDelay;
	if (threeSecDelay) {
		delay = 3000;
	} else {
		delay = 6000;
	}
	setTimeout(moveAlong, delay);
};
this line

threeSecDelay = !threeSecDelay;

toggles the boolean - threeSecDelay
neilmmm is offline   Reply With Quote
Old 04-15-2012, 06:36 PM   #4
mandog
Registered User
 
Join Date: Apr 2012
Posts: 7
Default

Quote:
Originally Posted by neilmmm View Post
you just make the delay a number variable

put an mc on the stage and call it toggleDelay_mc and put this code on a frame

may i also suggest you use setTimeout instead of setInterval - it works like setInterval but setTimeout is only called once and does not therefore have to be cleared

Code:
var threeSecDelay:Boolean = false;
var delay:Number;
function moveAlong():Void {
	//play();
	trace("delay = "+delay);
}
toggleDelay_mc.onRelease = function() {
	trace("pressed");
	threeSecDelay = !threeSecDelay;
	if (threeSecDelay) {
		delay = 3000;
	} else {
		delay = 6000;
	}
	setTimeout(moveAlong, delay);
};
this line

threeSecDelay = !threeSecDelay;

toggles the boolean - threeSecDelay
Beat me too it! I searched google and this forum and flashkit down to the strip but I couldn't find anything on AS2 then I remembered you can do this with a movie clip.
But I would recommend and adding some '//' to the code (because the OP is obviously going to copy and paste it) so you can teach this guy some things.
Such as

trace("pressed");
// This will make the word 'pressed' in the output panel on release.

'//' are comments, if you didn't know of course.
mandog is offline   Reply With Quote
Old 04-15-2012, 07:31 PM   #5
neilmmm
Senior Member
 
neilmmm's Avatar
 
Join Date: Oct 2005
Location: dorset
Posts: 1,637
Default

you want to comment my code go ahead

i assume people understand or people request clarification
neilmmm is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:53 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.