I have two movieclips this is based off of. work_mc and workss_mc
Work_mc is a collection of thumbnails on one frame.
Workss_mc is a collection of larger images with descriptions that has to ability to scroll through each slide
The way you navigate this is you click in work_mc, whatever thumbnail you choose and it will open workss_mc.
Once you are inside of work_mc you can view the image, go back(which takes you back to work_mc) or you have prev and next
Workss_mc consistants of multiple frames and each frame has a different image on it.
var workss_mc = new mc_workss(); newClassRoot.showModalContent(workss_mc); workss_mc.x=225; workss_mc.y=200; workss_mc.gotoAndStop("twentythreemotion"); workss_mc.addEventListener("closeButtonClick10", onCloseClick10);
}
function onCloseClick10(e:Event):void{ var work_mc = new mc_work(); newClassRoot.showModalContent(work_mc); work_mc.x=225; work_mc.y=130; }
So this should go to twentythreemotion and stop, which it does and it works correctly.
However, once you are in workss_mc the prev and next button are not functioning properly.
If you click on the first thumbnail and start the show from the beginning: This is on frame 1 of workss_mc..
Actionscript Code:
var a:Array=["urban","twentythree","citibrochure","csccard","rokroom","hiphop","metal","vangogh"]; var currentIndex:int=0; worknextbtn_mc.addEventListener(MouseEvent.CLICK, worknextClicked); function worknextClicked(event:MouseEvent){ currentIndex++; if(currentIndex>=a.length){ currentIndex=0; } gotoAndStop(a[currentIndex]); }
workprevbtn_mc.addEventListener(MouseEvent.CLICK, workprevClicked); function workprevClicked(event:MouseEvent){ currentIndex--; if(currentIndex>=a.length){ currentIndex=0; } gotoAndStop(a[currentIndex]); }
This works correctly if I choose the first thumbnail that goes to frame one but if I choose another thumbnail on work_mc that will go to a different frame label in workss_mc the prev/next buttons won't function properly..
I immediately see one error, but I don't think it's the one you're talking about. Since you are checking for currentIndex>=a.length in workprevClicked, it won't loop around when going backwards. That code actually needs to test whether it is <0 and if so set it to a.length -1.
What is probably happening with workss_mc is that if you don't go to the first frame, the code on that frame isn't executed and the buttons don't get set up.
If you have a class for workss_mc, then you could move that code into the class and call it from the constructor, ensuring that it will always have been executed. Be sure to set currentIndex correctly on each frame though. You could change the currentIndex stuff to calculate from the current frame label.
Code:
var a:Array=["urban","twentythree","citibrochure","csccard","rokroom","hiphop","metal","vangogh"];
worknextbtn_mc.addEventListener(MouseEvent.CLICK, worknextClicked);
function worknextClicked(event:MouseEvent) {
var currentIndex:int = a.indexOf(currentFrameLabel);
currentIndex++;
if (currentIndex>=a.length) {
currentIndex=0;
}
gotoAndStop(a[currentIndex]);
}
workprevbtn_mc.addEventListener(MouseEvent.CLICK, workprevClicked);
function workprevClicked(event:MouseEvent) {
var currentIndex:int = a.indexOf(currentFrameLabel);
currentIndex--;
if (currentIndex>=a.length) {
currentIndex=0;
}
gotoAndStop(a[currentIndex]);
}
Then you've got two options:
1. make the mc_workss class. shouldn't be too difficult.
or
2. make mc_workss a container which has a movieclip inside it which is the current mc_workss. That out clip will set up the buttons and listeners, and will have a method to advance the inner clip to the correct frame. Use that method instead of gotoAndStop from work_mc.
I don't usually use the IDE, so I'm not 100% on how to properly get the class to refer to ide-placed children. I think this should work, though:
Code:
package {
//add imports here
public class mc_workss extends MovieClip{
private var a:Array;
public var worknextbtn_mc:MovieClip;
public var workprevbtn_mc:MovieClip;
public function mc_workss(){
a = ["urban","twentythree","citibrochure","csccard","rokroom","hiphop","metal","vangogh"];
init();
}
private function init():void{
worknextbtn_mc.addEventListener(MouseEvent.CLICK, worknextClicked);
workprevbtn_mc.addEventListener(MouseEvent.CLICK, workprevClicked);
}
private function worknextClicked(event:MouseEvent):void {
var currentIndex:int = a.indexOf(currentFrameLabel);
currentIndex++;
if (currentIndex>=a.length) {
currentIndex=0;
}
gotoAndStop(a[currentIndex]);
}
private function workprevClicked(event:MouseEvent) {
var currentIndex:int = a.indexOf(currentFrameLabel);
currentIndex--;
if (currentIndex<0) {
currentIndex=a.length - 1;
}
gotoAndStop(a[currentIndex]);
}
}
}
If you get errors about worknextbtn_mc is null, let me know. We might have to get them by name in the init.
More or less. It's important to set up the buttons in the class as well, since the whole reason stuff wasn't working was that they weren't getting listeners added when you skip frame 1.
Line 59 1013: The private attribute may be used only on class property definitions.
Line 66 1013: The private attribute may be used only on class property definitions.