Skip to main content
Participating Frequently
April 17, 2013
Answered

Reverse Button Action from Frame 130 to 100

  • April 17, 2013
  • 2 replies
  • 4898 views

This is driving me up the wall, I have yet to finish the problem.

I am creating a presentation that simply scrolls text and a background image from right to left when I click a button. Simple enough, but all hell breaks loose when I want to do this in reverse. I can use the GoToAndPlay command, but this looks pretty unprofessional since it's used in a presentation in the event that I might have to go back. I'd rather flow than snap.

I literally am about to go crazy, and don't tell me to make a layer to fake a reverse.

I was able to start going backwards, but not stop, and I barely know the code yet. Been awhile since I opened this tedious program.

Button is called Backwards1.

This topic has been closed for replies.
Correct answer Ned Murphy

The forward code doesn't help show what you did wrong, especially if it works. 

As I described, to go backwards along the timeline you need to continuously step back a frame at a time until you reach the destination frame.  To continuously process something at the frame rate of your file you can use an ENTER_FRAME event listener.

Backwards1.addEventListener(MouseEvent.CLICK, goBack);

function goBack(evt:MouseEvent):void {

      this.addEventListener(Event.ENTER_FRAME, stepBack);

}

function stepBack(evt:Event):void {

      if(currentFrame == 100){

           this.removeEventListener(Event.ENTER_FRAME, stepBack);

      } else {

           prevFrame();

      }

}

2 replies

Participant
January 31, 2016

Mr. Ned Murphy thank you very much. The code work perfectly, you saved my day. To others do not forget to change the name to the correct button "that you have", and change number of frame to one you want to stop at "here 100 and 120". Also if there more than one button the code should have another number like these two examples "to avoid duplicate error"

Backwards1.addEventListener(MouseEvent.CLICK, goBack_1);

function goBack_1(evt:MouseEvent):void {

      this.addEventListener(Event.ENTER_FRAME, stepBack_1);

}

function stepBack_1(evt:Event):void {

      if(currentFrame == 100){

          this.removeEventListener(Event.ENTER_FRAME, stepBack_1);

      } else {

          prevFrame();

      }

}

>>>>>

Backwards1.addEventListener(MouseEvent.CLICK, goBack_2);

function goBack_2(evt:MouseEvent):void {

      this.addEventListener(Event.ENTER_FRAME, stepBack_2);

}

function stepBack_2(evt:Event):void {

      if(currentFrame == 120){

          this.removeEventListener(Event.ENTER_FRAME, stepBack_2);

      } else {

          prevFrame();

      }

}

Participant
September 15, 2019
Hi, there! the example was so usefull!!! can you show us the same code for forward?
Ned Murphy
Legend
April 17, 2013

Show the cvode you are trying to use for this button.  It should involve continuously calling a prevFrame() function until you reach a particular frame.

Participating Frequently
April 17, 2013

Well that's the probelm, I don't have any code since i've scrapped every attempt, but here's the code for the forward:

Forward2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_32);

function fl_ClickToGoToAndPlayFromFrame_32(event:MouseEvent):void

{

          gotoAndPlay(911);

}

Chipleh
Inspiring
April 17, 2013

You could try using Greensock's TimeLineLite; the example on the page has a demo of play and reverse: http://www.greensock.com/timelinelite/

It's only library I use for animating.