0
votes

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.

1
I'm assuming you mean you want to start by showing MC1 and MC2 and MC3 are hidden? And when next is clicked, MC2 is shown, and MC1 and MC3 hidden, and so on? If so that is very trivial. Simply alter the value of the visible property for each of the MovieClips. When visible = true the movieclip is shown on the screen, when it's false it'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
@MDMoura, your question is interesting and not so simple. Here is my answer... - helloflash

1 Answers

0
votes

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).