Skip to main content
bipb66900846
Participant
May 21, 2015
Question

Multiple previous/next buttons in actionscript 3.0?

  • May 21, 2015
  • 2 replies
  • 1127 views

first off all, I'm incredibly new to flash and actionscript 3 (I literally had never even touched flash until last week), so I'm sorry if this is a silly question.

basically my problem is this:

I need to make several sets of previous/next buttons that each control different sets of images/keyframes. I already know how to make 1 set of buttons, but I'm not entirely sure how to add more without having them affect ALL the images instead of the ones I need them to. (like I said, I'm really new to coding, so I'm not sure how to make the buttons respond to a specific root)

This topic has been closed for replies.

2 replies

Known Participant
July 19, 2015

Sample back and next button

stop();

btnNext.addEventListener(MouseEvent.CLICK, puntaNext);

function puntaNext(m:MouseEvent)

{

  var frameNgayon:int;

  frameNgayon = this.currentFrame;

  gotoAndStop(frameNgayon + 1);

}

btnBack.addEventListener(MouseEvent.CLICK, puntaBack);

function puntaBack(m:MouseEvent)

{

  var frameNgayon:int;

  frameNgayon = this.currentFrame;

  gotoAndStop(frameNgayon - 1);

}

Ned Murphy
Legend
May 21, 2015

There are a variety of ways one might implement a previous / nest scenario.  Very often it can be realized using just one button for each direction of play.  If you explain how you have things set up it will be easier to try to help. 

bipb66900846
Participant
May 21, 2015

well, this time around I'm aiming to make a simple customizer/dress up game that uses buttons to switch between items. my current set up has all the different items + the code distributed throughout several keyframes on the same layer. this is the code I'm using :

button1.addEventListener(MouseEvent.CLICK, backward);

button2.addEventListener(MouseEvent.CLICK, forward);

function forward(event:MouseEvent) {

  if (this.currentFrame == this.totalFrames) {

  gotoAndStop(1);

  }

  else {

  nextFrame();

  }

}

function backward(event:MouseEvent) {

  if (this.currentFrame == 1) {

  gotoAndStop(this.totalFrames);

  }

  else

  {

  prevFrame();

  }

}

(of course, I don't really need both buttons, but I'm using the full code for now)

the code works fine, but like I said I can only get it to work for one set of buttons. so let's say that I want to be able to change between a set of different shirts and a set of different pants. I'm able to make a button/buttons that works for the shirts, but I don't know how to make an additional button that only changes the pants. basically, I need to stop the button for shirts and the button for pants from interfering with each other.

(I'm sorry if this wasn't the info you needed, or if I didn't explain it properly. as I said, I'm new to this, and this is mostly just practice for a bigger project I have planned)

Ned Murphy
Legend
May 21, 2015

For the code you show, that code could be used to manage the entire timeline if you just leave it in frame 1 and have that layer and the buttons that relate to it extend the full length of the timeline.  So you will have the same two buttons to control movement for the entire timeline... no need to repeat them anywhere because they will then exist everywhere.

I have no idea how that code relates to choosing shirts and pants since it appears to do nothing of the sort.