0
votes

I have a slideshow with 4 pictures and runs on a timer. I have a movie clip called play_mc. Inside the movie clip is a button with an instance name of play_btn on keyframe 1. Then on keyframe 2 there is another button with an instance name pause_btn. On the AS3 layer, I have this code:

stop();

play_btn.addEventListener(MouseEvent.CLICK, goToPause);
function goToPause(Event:MouseEvent){
    gotoAndStop(2);
}

pause_btn.addEventListener(MouseEvent.CLICK, goToPlay);
function goToPlay(Event:MouseEvent){
    gotoAndStop(1);
}

On the main stage on the as3 layer, I have this code (this is not all of the code - all other code works without the play_mc movie clip)

myTimer.addEventListener(TimerEvent.TIMER, autoAdvance);
function autoAdvance(event:TimerEvent){
    if(imageNumber<totalImages){
        imageNumber++;
    }
    else(imageNumber = 1);
    reload();
}

function reload(){
    removeChild(myLoader);
    myRequest = new URLRequest(imageNumber + ".jpg");
    myLoader.load(myRequest);
    addChildAt(myLoader, 1);
}

play_mc.addEventListener(MouseEvent.MOUSE_DOWN, stopTimer);
function stopTimer(event:Event){
    myTimer.stop();
}
play_mc.addEventListener(MouseEvent.MOUSE_DOWN, resumeTimer);
function resumeTimer(event:Event){
    myTimer.start();
}

I get an error saying:

TypeError: Error #1009: Cannot access a property or method of a null object reference. at gallery_fla::play_Mc_3/frame1()

Basically when I click on the Play button the slideshow starts and the text changes to "Pause" but when I click again, the slideshow does not pause and the text won't change back to "Play".

Anyone have an idea how to help me out here, please??

1

1 Answers

0
votes

You've created the pause button eventListener on the frame where the button doesn't exist. Try placing this

pause_btn.addEventListener(MouseEvent.CLICK, goToPlay);
function goToPlay(Event:MouseEvent){
    gotoAndStop(1);
}

on frame two which has the pause button on it.

edit:

instead of creating two listeners on play_mc, just create one and then base the actions on a switch i.e.

var _playToggle:Boolean = true;

play_mc.addEventListener(MouseEvent.MOUSE_DOWN, switchTimer);

function switchTimer(event:Event){
    if(_playToggle){
        myTimer.start();
    }else{
        myTimer.stop()
    }
    _playToggle = !_playToggle;
}