Hi, I am not for sure if I am posting in the correct room. I have a flash photo gallery question. I am making a flash webpage using CS4 using a previous and next button. Both the previous and next button work but one problem. It does not stop at the first gallery instead it goes all the way to the end to the very last gallery. Example. One gallery is name food, the next family, and after sports, and etc. The next and previous button goes to the next gallery without stopping.

My question is, is there a way that I can make it stop so that it stop at the very end of each gallery instead of jumpin over to the next?

This is my code that I use.

stop ();

Previousbtn.addEventListener (MouseEvent.CLICK, backward);
Nextbtn.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();
}
}

Dani AI

Generated

Short summary: the wrap-around you saw happens because the handlers are looking at the whole movie (totalFrames / frame 1) instead of the bounds of the current gallery. @LastMitch was right to check that you had a stop() in the timeline; discovered the quick fix by testing explicit frame numbers. For a maintainable solution, treat each gallery as a bounded range (or give each gallery a frame label) and make the next/previous handlers enforce those bounds instead of using totalFrames.

Example pattern (ActionScript 3) — put this on the main timeline and replace prevBtn/nextBtn with your instance names:

import flash.events.MouseEvent;

var galleries:Array = [
  {name:"food",  start:1,  end:10},
  {name:"family",start:11, end:20},
  {name:"sports",start:21, end:30}
];

var currentIndex:int = -1;

function findIndex(frame:int):int {
  for (var i:int=0;i<galleries.length;i++) {
    var g:Object = galleries[i];
    if (frame >= g.start && frame <= g.end) return i;
  }
  return 0;
}

function refresh():void {
  currentIndex = findIndex(this.currentFrame);
}

prevBtn.addEventListener(MouseEvent.CLICK, onPrev);
nextBtn.addEventListener(MouseEvent.CLICK, onNext);

function onNext(e:MouseEvent):void {
  var g:Object = galleries[currentIndex];
  if (this.currentFrame < g.end) this.nextFrame();
  // else: at gallery end — do nothing or disable nextBtn
  refresh();
}

function onPrev(e:MouseEvent):void {
  var g:Object = galleries[currentIndex];
  if (this.currentFrame > g.start) this.prevFrame();
  refresh();
}

refresh();

Troubleshooting & tips: use frame labels instead of hard numbers if you add frames later; alternatively put each gallery inside its own MovieClip and stop() the clip so navigation can’t leak out. If buttons behave oddly, confirm the script is on the main timeline (or explicitly reference MovieClip(root)) so currentFrame refers to the right timeline. Disable the next/prev button at gallery edges (e.g., nextBtn.mouseEnabled = false and lower alpha) for clearer UX.

Recommended Answers

All 2 Replies

Member Avatar for Member #949455

It does not stop at the first gallery instead it goes all the way to the end to the very last gallery.

There's nothing wrong with your code.

Did you insert the stop(); in key frame 1?

Hi LastMitch yes I did. I stayed up until 3 am and solve it. I have been working on my photo porfolio page for over 6 months and save this for last. Well not really last I have a few bugs left to fix. The problem was that I needed to tell the actionscript which frames forward and which frames backward to sow. Since I have the total frame of 45 it was showing the total frame. Therefore, where it say in total.Frame something in me told me to try a number and I did the same for the gotoStop and it work. After it workd I did the same to the rest but had to change the random of the numbers because then one gallery was going backward into the gallery before or continue to go forward into the next gallery.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.