AS3 movieclip slideshow

Hello

I am trying to create a flash AS3 slideshow with an array of movieclips. On the main stage there is only a next and previous button, with the instance names btnNext and btnPrev respectively. Each slide is a movieclip that has been created in the library, none are on stage. I would like to, at the start of the slideshow, load the first movieclip/slide on stage, and then when the user either clicks anywhere on the stage, or presses the next button, go to the next slide/movieclip. If the user clicks on the previous button, go to the previous slide/movieclip.

The thing is, I want the movieclip/slide currently on stage to finish playing through its animation before the next and previous buttons become visible again, and also so that the user can’t click the stage to advance a slide until the current slide is finished.

Inside each slide movieclip I have added this on the last frame (to create an event for when the movieclip/slide is done playing) :
stop();
dispatchEvent(new Event(“done”));

The movieclips in the library are named IntroClip(), Slide0Clip(), Slide1Clip() etc. (these are just the names of the movieclips, not their instance names - I would like to access the instance names dynamically. See code below)

This is what I have so far, any help would be really appreciated to get this to work. Unfortunately my deadline is tomorrow (my bad, I know :slight_smile: just been so busy trying to get this to work myself). This code is all on the first frame of the main timeline.


    //create the array of movieclips/slides
    var slides:Array = new Array(7);
    slides[0] = new IntroClip();
    slides[1] = new Slide0Clip();
    slides[2] = new Slide1Clip();
    slides[3] = new Slide2Clip();
    slides[4] = new Slide3Clip();
    slides[5] = new Slide4Clip();
    slides[6] = new Slide5Clip();
    
    // Each clip will have upper left corner at (50,50)
    for (var i=0; i < slides.length; i++) {
        slides*.x = 50;
        slides*.y = 50;
    }
    
    // Declare global variables
    var index:int = 0;

    // Place first (IntroClip) clip on the stage.
    addChild(slides[index]);
    btnNext.visible = false;
    btnPrev.visible = false;

    //add listeners to advance (either by clicking stage or next button) or go to previous slide
    stage.addEventListener(MouseEvent.CLICK, goNext);
    btnNext.addEventListener(MouseEvent.CLICK, goNext);
    btnPrev.addEventListener(MouseEvent.CLICK, goPrev);
 
    //function to advance to next slide
    function goNext(event:MouseEvent):void {
        //remove slide change functionality
        stage.removeEventListener(MouseEvent.CLICK, goNext);
        btnNext.visible = false;
        btnPrev.visible = false;
        
        //add the listener for when current slide movieclip animation is done, then execute slideDone function
        (slides[this]).addEventListener("done", slideDone);
        
        //remove the current slide from stage
        removeChild(slides[index]);
        
        //increment the array position to the next slides position
        index++;
        
        //add the next slide to stage
        addChild(slides[index]);
}

    //function to go to previous slide
    function goPrev(event:MouseEvent):void {
        //remove slide change functionality
        stage.removeEventListener(MouseEvent.CLICK, goNext);
        btnNext.visible = false;
        btnPrev.visible = false;
        
        //add the listener for when current slide movieclip animation is done, then execute slideDone function
        (slides[this]).addEventListener("done", slideDone);
        
        //remove the current slide from stage
        removeChild(slides[index]);
        
        //decrement the array position to the previous slides position
        index--;
        
        //add the previous slide to stage
        addChild(slides[index]);
}

    //function to activate the buttons and stage clicking functionality when the current slide/movieclip is done animating
    function slideDone(event:Event):void {
        btnNext.visible = true;
        btnPrev.visible = true;
        stage.addEventListener(MouseEvent.CLICK, goNext);
}