I have 3 MCs in a stage: MC1, MC2 and MC3.
And I have two buttons: Next and Prev.
When I click the Next or Prev buttons I would like to show the next or previous MC.
How can I do this? I am using Flash and ActionScript 3.0.
You can do that. If you assume you have 3 MovieClips on your scene, named MC1, MC2 and MC3:
const N:uint = 3; // number of instances
for (var i:int = 1; i <= N; i++) {
MovieClip(this["MC" + i]).visible = false;
}
var n:uint = 3; // index of the last instance
var __last:MovieClip = MovieClip(this["MC" + n]); // first visible instance
__last.visible = true;
Next.addEventListener(MouseEvent.CLICK, gotoNext);
function gotoNext(e:MouseEvent):void {
__last.visible = false; // set invisible the last instance
if (n < N) n++;
__last = MovieClip(this["MC" + n]); // set visible the new instance
__last.visible = true;
}
Prev.addEventListener(MouseEvent.CLICK, gotoPrev);
function gotoPrev(e:MouseEvent):void {
__last.visible = false;
if (n > 1) n--;
__last = MovieClip(this["MC" + n]);
__last.visible = true;
}
You can change your 'n' value to decide your first visible instance (1, 2 or 3).
visibleproperty for each of the MovieClips. Whenvisible = truethe movieclip is shown on the screen, when it'sfalseit's not shown. Unless you show some code showing what you've tried so far, most aren't going to just write a bunch of free code for you. - Anil Natha