View Full Version : Delaying Actionscript
aussie01
12-09-2005, 11:23 AM
Can you delay actionscript so that it executes on a specific frame?
I have an animation and a button on the stage. I want the button to do something, but only when the animation gets to a certain point. So I've made the main timeline 60 frames long (my animation in embedded in a movie clip that loops every 60 frames) yet my actionscript is on frame 1.
If the button is pressed anywhere between frame 1 and 59 the animation jumps to the target of the button, whereas frame 60 of the first animation and frame 1 of the second (which the button links to) glide seamlessly. Can I write some code that will say something like...
"Do what I ask, but wait until frame 60 to do it"?
Cheers,
saumya
12-09-2005, 11:55 AM
ya, whay not?
for that you have to play arround with
_currentframe
property of the _root.
that will give you the frame number.Now take that number and do whatever you want to do with the frame number.Basically i think you will have to write
if(_root._currentframe>=60){
myBtn.onRelease=function(){
trace("i am clicked");
}
}
aussie01
12-09-2005, 12:09 PM
Hi,
The code you wrote didn't seem to work. What I have below is the code I am using. It's all in the first frame of the main timeline.
green_mc is a button
red_mc is a button
loop_mc is an animation in a movie clip
nextloop_mc is an animation in a movie clip
nextloop2_mc is an animation in a movie clip.
I want the code below to only activate on frame 60. The _currentframe didn't seem to work.
Thanks for any help.
var spinning:Boolean = true;
var controlcolor:Color = new Color(green_mc);
var controlcolor:Color = new Color(red_mc);
green_mc.onRollOver = function(){
this._xscale = 120;
this._yscale = 120;
}
green_mc.onRollOut = function(){
this._xscale = 100;
this._yscale = 100;
}
green_mc.onRelease = function(){
if (spinning){
loop_mc._visible = false;
loop_mc.stop();
nextloop_mc._visible = true;
nextloop_mc.gotoAndPlay(2);
red_mc._visible = false;
green_mc._visible = true;
spinning = false;
controlcolor.setRGB(0x0fe50f);
}else{
loop_mc._visible = true;
loop_mc.gotoAndPlay(1);
nextloop_mc._visible = false;
red_mc._visible = true;
green_mc._visible = true;
spinning = true;
controlcolor.setRGB(0xffd4ff);
}
}
red_mc.onRollOver = function(){
this._xscale = 120;
this._yscale = 120;
}
red_mc.onRollOut = function(){
this._xscale = 100;
this._yscale = 100;
}
red_mc.onRelease = function(){
if (spinning){
loop_mc._visible = false;
loop_mc.stop();
nextloop2_mc._visible = true;
nextloop2_mc.gotoAndPlay(2);
green_mc._visible = false;
spinning = false;
controlcolor.setRGB(0x0fe50f);
}else{
loop_mc._visible = true;
loop_mc.gotoAndPlay(1);
nextloop2_mc._visible = false;
green_mc._visible = true;
spinning = true;
controlcolor.setRGB(0xffd4ff);
}
}
saumya
12-09-2005, 12:13 PM
in the first frame just put the code below and see whats it giving
trace(_root._currentframe);
aussie01
12-09-2005, 12:17 PM
The output says 1 every 60 frames.
Scottae
12-09-2005, 03:48 PM
You can set a variable one the button is pressed. Then on frame 60, have an if else statement to do something that is dependant on that variable. So for example, create a variable on frame one:
// Check to see if the variable exists. If not,
// then set it to false. We only want this to
// happen the first time it gets to this frame.
// From here on out, myVariable will be defined.
if (myVariable == undefined)
var myVariable:Boolean = false;
Then on the button, just set the myVariable to true. Finally, on frame 60 put this code:
// This will only execute if the button was pressed
if (myVariable)
{
// Reset it to false
myVariable = false;
// Have code here that does what you want
//...........................
trace ("worked");
}
vBulletin v3.5, Copyright ©2000-2010, Jelsoft Enterprises Ltd.