PDA

View Full Version : Forward and backward buttons on movie



firstborn01
February 24th, 2004, 12:34 AM
well what i am trying to do is move between 2 text boxes through a motion tween. but thats not going to work because you can't tween backwards. so what would be the best thing to do?

this has probably been posted before but i have no idea where it is. i tried the sliding menu tute but that didn't work. i'd appriciate any help.

dave

claudio
February 24th, 2004, 12:40 AM
You can play a timeline backwards using AS.

firstborn01
February 24th, 2004, 08:30 AM
yes, i know but what i need is for it to play backwards when you press a button. can anyone tell me the action script for this? i tried


on (release) {
prevFrame();
}


but that only plays one frame.... i need it to go all the way back.

Voetsjoeba
February 24th, 2004, 08:33 AM
MovieClip.prototype.playBackwards = function(){
this.stop();
this.onEnterFrame = function(){
this.prevFrame();
if(this._currentframe == 1){
delete this.onEnterFrame;
}
}
}
// Usage:
yourMC.playBackwards();


So with your button, the code would look like this:


on(release){
yourMC.playBackwards();
}


Of couse, make sure you use the correct path for yourMC :)

firstborn01
February 24th, 2004, 02:11 PM
thanks voets... but ehre do i put that first bit of code?

Voetsjoeba
February 24th, 2004, 02:25 PM
I mostly place prototype methods on the first frame of the main timeline. That way, the method is available to all movieclips from the first frame on :)

firstborn01
February 24th, 2004, 10:44 PM
ok... so what do you do to play the movie? i'm sorry, i am horrible at actionscript.

Voetsjoeba
February 25th, 2004, 02:55 AM
You wanted it to play backwards onRelease of a button right ? Then place this code on your button:



on(release){
yourMC.playBackwards();
}


Where yourMC is the movieclip to play backwards :)

So the prototype method goes on the first frame, and the code that actually uses it can be used anywhere throughout your movie.

firstborn01
February 25th, 2004, 08:33 AM
yea, i got that. but what if i want to push another button and have it play forwards?

Voetsjoeba
February 25th, 2004, 08:46 AM
on(release){
delete yourMC.onEnterFrame;
yourMC.play();
}


Where yourMC is the movieclip playing backwards :)

firstborn01
February 25th, 2004, 12:57 PM
ok, i can't get this to work at all. i have the main code in my main timeline. the button codes in the correct buttons and i changed all of the "myMC" or whatever to the name of my movie. nothing works. what am i doing wrong?

Voetsjoeba
February 25th, 2004, 01:29 PM
I can't tell without seeing the file ...

firstborn01
February 25th, 2004, 10:31 PM
ok, here is a basic fla. now don't laugh... i really hate actionscript. i think it is way to confusing... but alas, i need it. thanks for your help.

rob_bie
February 27th, 2004, 03:26 PM
sorry to jump in on this thread, it's just that i took a look at your code, and not wanting to come accross as some kind of expert (which i'm most definately not!) i noticed that you have forgotten to give an instance name to your movie clip. you reference the instance "movie" in your actionscript e.g.

movie.playBackwards();

so you need to set the instance name of the movieclip to "movie.

<<click on the layer "movie" under the mask layer and then click on the movieclip instance on the stage and set the instance variable in the property section to "movie" and it all works>>

hope that helps you out.

firstborn01
February 28th, 2004, 12:19 AM
oh man, i totally didn't even think of that!! thank you so much! if you are always this helpful you can jump into any thread you want. thanks again.
dave