Rewind animations in Flash CS3 - actionscript-3

I have made an animation in Flash CS3 and i need to reverse this in the timeline.
I tried this, but it did not work:
if(!this.flag)
{
this.flag=1;
this.stop();
this.fwd_btn.addEventListener("click", fl_MouseClickHandler.bind(this));
function fl_MouseClickHandler() {
this.on("tick", ffwd.bind(this));
}
this.rew_btn.addEventListener("click", fl_MouseClickHandler_2.bind(this));
function fl_MouseClickHandler_2() {
this.on("tick", rewind.bind(this));
}
function ffwd(e) {
this.gotoAndStop(this.currentFrame + 1);
}
function rewind(e) {
this.gotoAndStop((this.currentFrame + this.getDuration() - 1) % this.getDuration());
}
}
How can i do this by using Action Script code or by using the timeline functions?

You should try Greensock TweenMax with frame plugin, it allows you to go to a particular frame (even in reverse) very simply. You can also target a label.
TweenMax.to(this, 2, {frame:1});
//In 2 seconds, stage timeline will go to first frame.
Have a look here : http://www.snorkl.tv/2010/10/overview-of-tweenmax-framelabel-and-frame-plugins-nifty-way-to-play-a-flash-timeline-backwards/

Related

create js as3 flash canvas js frame code runs once

The js code generated in the files output in Adobe Animation for HTML5 Canvas contains an object for the movie clip that include the code that is to be run in each frame.
(lib.cdseacc02_07 = function(mode,startPosition,loop) {
// timeline functions:
this.frame_0 = function() {
if(typeof showNarration !== "undefined"){ showNarration(1); }
}
this.frame_644 = function() {
playSound("02_07_01wav");
}
this.frame_652 = function() {
this.closeBtn_1.addEventListener("click", closepopup_1.bind(this));
}
this.frame_738 = function() {
this.stop();
}
}).prototype = p = new cjs.MovieClip();
If gotoAndPlay is called on the movieclip from this code the code on the frame function is not run on the frames as they are passing by, this frame code only works the first time the timeline is played. Is there any way to make it so that the code on the frames can run each time the playhead passes that frame even if it was through a gotoAndPlay call in the code?
Frame actions should absolutely be played each time the timeline passes that frame, whether during gotoAndPlay or gotoAndStop. In fact, this sometimes causes issues where things event listeners are added multiple times (each time the framehead passes the script, like on your frame 652).
Can you post a simplified example of this not working?

Proceeding in Movieclip After Animation Finishes AS3

I have a Movieclip on my stage which contains two buttons: Back and Next. Also on the timeline, I have another Movieclip which contains an animation. After the next button is clicked, I'd like to have the animation transition into the next animation without jumping. So, is there any way I can listen for the animation to be finished so that I can time the transitions seamlessly?
Here is the code for my Next and Back buttons (which are movieclip buttons which is why there is all of the extra code) which just switch between frames as of now:
//NEXT BUTTON
nextBtn.buttonMode = true;
nextBtn.addEventListener(MouseEvent.ROLL_OVER, nextBtnOver);
nextBtn.addEventListener(MouseEvent.ROLL_OUT, nextBtnOut);
nextBtn.addEventListener(MouseEvent.MOUSE_DOWN, nextBtnDown);
nextBtn.addEventListener(MouseEvent.MOUSE_UP, nextBtnUp);
function nextBtnOver(e:MouseEvent):void
{
nextBtn.gotoAndPlay("over");
}
function nextBtnOut(e:MouseEvent):void
{
nextBtn.gotoAndPlay(9- (nextBtn.currentFrame-1));
}
function nextBtnDown (e:MouseEvent):void
{
nextBtn.gotoAndPlay("down");
}
function nextBtnUp (e:MouseEvent):void
{
nextBtn.gotoAndPlay(5);
MovieClip(root).nextFrame();
}
//BACK BUTTON
backBtn.buttonMode = true;
backBtn.addEventListener(MouseEvent.ROLL_OVER, backBtnOver);
backBtn.addEventListener(MouseEvent.ROLL_OUT, backBtnOut);
backBtn.addEventListener(MouseEvent.MOUSE_DOWN, backBtnDown);
backBtn.addEventListener(MouseEvent.MOUSE_UP, backBtnUp);
function backBtnOver(e:MouseEvent):void
{
backBtn.gotoAndPlay("over");
}
function backBtnOut(e:MouseEvent):void
{
backBtn.gotoAndPlay(9- (backBtn.currentFrame-1));
}
function backBtnDown (e:MouseEvent):void
{
backBtn.gotoAndPlay("down");
}
function backBtnUp (e:MouseEvent):void
{
backBtn.gotoAndPlay(5);
MovieClip(root).prevFrame();
}
Thanks, any help is appreciated.
If your animations are timelined, call an animationComplete function in the last frame of your animation movieClip. This function would live at the same scope as your posted code above, so you just have to be able to path to it properly from within the animation clip. For instance, if the code is one level outside the animation movieClip (the mc's parent) then you might call this.parent.animationComplete(), which would contain the code you want to execute when the animation finishes.
According to your comment,
I tried this, and it works - except in order for
it to advance to the next point you have
to click the next button at exactly the right frame.
I'd like to make it so you can click it at any point in the Movieclip, and it
will play the remainder of the Movieclip before proceeding
to the next frame. Here's my code for what I've added: function
nextBtnUp(e:MouseEvent):void {
nextBtn.gotoAndPlay(5); if (MovieClip(root).animationTest.currentFrame ==
MovieClip(root).animationTest.totalFrames) MovieClip(root).nextFrame();
}
Thank you for the help so far
You have it most of it figured out, so to finish can add stop() in the code at the last frame of your MovieClips, or you can do this (the more complex version):
yourClip.yourFirstClip.addEventListener(Event.ENTER_FRAME, stopAtLastFrame);
yourClip.yourSecondClip.addEventListener(Event.ENTER_FRAME, stopAtLastFrame);
function stopAtLastFrame(e:Event):void
{
if(e.currentTarget.currentFrame === e.currentTarget.totalFrames)
// ^Note that no conversion is being made, so you can have 3 equal signs
{
e.currentTarget.stop();
}
}

How do I play the animation from the current frame, ActionScript 3.0

I'm trying to make a personalized pause button for my flash animations.
This the code I have for it so far
var paused:Boolean = false;
pause.addEventListener(MouseEvent.CLICK, fl_PauseUnpause);
function fl_PauseUnpause(event:MouseEvent):void
{
if(paused=true)
{
stop();
paused=false;
}
else
{
gotoAndPlay(this.currentFrame);
paused=true;
}
}
Stopping the animation works just fine, but it will not start again afterwards. It gives no error when run.
if(paused=true) // this assigns true to paused and if always evaluates to true
That has to be :
if(paused==true) //or if(paused)
No?

Changing individual movieclip's frame rate with TweenMax

My aim is to change the frame rates of my individual (looping) movie clips through clickable controls (slow/med/fast). I've heard it isnt possible to achieve this through as3/flash alone, so I've tried greensock's TweenMax... However I can't seem to figure out how to do this. Is there anyone that could help?
box1.addEventListener(MouseEvent.MOUSE_DOWN, box1down);
function box1down(event:MouseEvent):void {
//FRAMERATE CODE HERE
}
Many thanks!
Here is the API doc for TweenMax: http://www.greensock.com/as/docs/tween/com/greensock/TweenMax.html
If you have multiple movieclips that you are trying to control, you can just create an abstract class with the functionality you want and extend that class. So something like:
public class ControlledMovieClip extends MovieClip {
public function ControlledMovieClip() {
stop();
}
public function animate(frameRateInSeconds:Number):void {
TweenMax.to(this, frameRateInSeconds, { frame: this.totalFrames - 1, repeat: -1, ease: Linear.easeNone });
}
}
Have all your movieclips that are looping extend that class, and then you could call the animate function on the objects in your box1down event handler.
I haven't tested that code so you might need a gotoAndStop(1) at the end of each iteration.
It's possible through Actionscript alone it just requires you to handle the frame progression yourself (instead of using mc.play() you stop the movieclip and call nextFrame() yourself).
Lets say a Movieclip (myMC) has 20 frames of animation. To manually run the animation at normal speed you simply call myMC.nextFrame(); on every frame of your project (using an ENTER_FRAME listener for example).
To have the animation run at half speed you can use a frame count and a frame trigger:
var frameTick = 0;
var frameAnimTrigger = 2;
function Update(e:Event):void
{
frameTick++;
if(frameTick == frameAnimTrigger)
{
myMC.nextFrame();
frameTick = 0;
}
}
Because nextFrame is only called every other frame the animation appears to run at half speed.

Flash CS5 Actionscript 3.0 Go to Next Frame and Play Code

I am coding a simple movie timeline in Flash CS5 actionscript 3.0. I have all my buttons working except for the Play button which I would like to code to say "go to next frame and play". Here is my current actionscript can anyone help me to find the correct code?
fastforwardBtn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame);
function fl_ClickToGoToAndStopAtFrame(event:MouseEvent):void
{
gotoAndStop(4025);
}
stop();
gotoStopBtn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_2);
function fl_ClickToGoToAndStopAtFrame_2(event:MouseEvent):void
{
gotoAndStop(1);
}
gotoPlayBtn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame);
function fl_ClickToGoToAndPlayFromFrame(event:MouseEvent):void
{
gotoAndPlay(1);
}
stopBtn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextFrame_2);
function fl_ClickToGoToNextFrame_2(event:MouseEvent):void
{
nextFrame();
}
playBtn.on (release) ;{
_root.gotoAndPlay(_currentframe+1);
}
playBtn.addEventListener(MouseEvent.CLICK, fl_Click_Play);
function fl_Click_Play(event:MouseEvent):void
{
MovieClip(root).play();
}
should work, if you have a simple fla. And if that doesn't seem to work, you may need something like this to target the right path:
MovieClip(this.parent).play();
Without knowing your fla structure, its just a guess ;)
also = _root is AS2, and always targets _level0. This is changed in AS3 to just "root", and targets the timeline of the topmost displayObjectContainer.