PDA

View Full Version : how to create a time delay prototype script



julietling
May 29th, 2004, 12:49 AM
problem:
how to create a time delay prototype script.

situation:
click on buttons to run a display mc1 after 2 sec delay

//script on button//
on (press) {
_root.mc1.wait();
}


script needed:

MovieClip.prototype.wait = function() {
_root.mc1.gotoAndPlay(2);
this.clearInterval(this.setInterval(wait, 2000));
}

thanks

Adam
May 29th, 2004, 12:53 AM
function wait(){
_root.mc1.gotoAndPlay(2);
clearInterval(IDName)
}

on button:
on (press) {
IDName=setInterval(wait, 2000);
}

Adam

julietling
May 29th, 2004, 11:10 AM
thanks, adam

i'm freakin new to actionscript, i hv no idea what is the code i wrote in my question :)

julietling
May 29th, 2004, 12:28 PM
sorry for not being clear, i actually need to target the
gotoAndPlay(2) to many MCs. I wanted on press of a button, the MC (say, clipA) indicated on the event handler of the button invoke moving the playhead to frame 2 inside clipA
and so on..

//button 1//
on (press) {
_root.clipA.wait();
}

//button 2//
on (press) {
_root.clipB.wait();
}

//button 3//
on (press) {
_root.clipC.wait();
}

and so on..

thanks

Adam
May 29th, 2004, 12:38 PM
You could assign variables to each button such as"

on the button that plays clipA

on (press) {
clipName="A"
IDName=setInterval(wait, 2000);
}

and the button that plays clipB

on (press) {
clipName="B"
IDName=setInterval(wait, 2000);
}

And then you could set your function up and use this variable clipName in it to target the clip you want to play:

function wait(){
_root["clip"+clipName].gotoAndPlay(2);//clipName will return A or B
clearInterval(IDName)
}

should work for ya ;)

Adam

julietling
May 29th, 2004, 10:06 PM
how do i change the script to work if the function is on the main timeline while the button is in another mc,
since the on (press) can't find the function inside the mc?