# Pause button doesn't always work

**URL:** <https://forum.kirupa.com/t/pause-button-doesnt-always-work/313781>\
**Category:** Uncategorized\
**Created:** [September 9, 2010, 1:45pm UTC](https://forum.kirupa.com/t/pause-button-doesnt-always-work/313781 "2010-09-09T13:45:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lanawylma](https://avatars.discourse-cdn.com/v4/letter/l/58f4c7/32.png) [@lanawylma](https://forum.kirupa.com/u/lanawylma)\
**Post date:** [September 9, 2010, 1:45pm UTC](https://forum.kirupa.com/t/pause-button-doesnt-always-work/313781/1 "2010-09-09T13:45:07Z")

</div>

HI All…

I have a slide-show with 3 sections. The slide-show loops automatically as well as when being prompted by a button to go to a particular section. I also added a play/pause button which works initially, however, when clicked on one of the buttons to go to another section, the slide-show resumes looping…

I"m assuming I need to check weather the pause button has been clicked to resume/or not resume the slide-show… but I’m unable to figure out how to do that. Any help would be super appreciated! - Thanks a lot ahead of time! Here’s the code:

import fl.transitions.Tween;  
import fl.transitions.TweenEvent;  
import fl.transitions.easing.\*;

//Timer  
var tl:MovieClip = this;  
var slideDuration:uint = 12000;// or use whatever  
var slideTimer:Timer=new Timer(slideDuration,0);  
slideTimer.addEventListener(TimerEvent.TIMER,autoA dvanceF);

var previousBtn:SimpleButton;

go\_btn.addEventListener(MouseEvent.CLICK, startPlaying);  
pause\_btn.addEventListener(MouseEvent.CLICK, stopPlaying);

var btnA:Array = [one\_btn,two\_btn,three\_btn];

go\_btn.visible = false;

function autoAdvanceF(e:TimerEvent):void {  
nextButtonF(previousBtn).dispatchEvent(new MouseEvent(MouseEvent.CLICK));  
}

function nextButtonF(btn:SimpleButton):SimpleButton {// use class type of your buttons  
for (var i:uint=0; i\<btnA.length; i++) {  
if (btnA\*==btn) {  
return btnA[(i+1)%btnA.length];  
}  
}  
return null;  
}

//Load external SWF into main  
var Xpos:Number = 0;  
var Ypos:Number = 0;  
var loaderA:Array = [];

//Btns universal function (whenver any button is clicked, the loader will be removed

function stopPlaying(event:MouseEvent):void {

```
slideTimer.stop();
go_btn.visible = true;
pause_btn.visible = false;

```

}

function startPlaying(event:MouseEvent):void {

```
slideTimer.start();
go_btn.visible = false;
pause_btn.visible = true;

```

}

function btnClick(event:MouseEvent):void {

```
slideTimer.reset();
slideTimer.start();

previousBtn = SimpleButton(event.currentTarget);

var loader:Loader = new Loader();
loaderA.push(loader);

var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf");
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE,loadComplete );

loader.load(newSWFRequest);
loader.x = Xpos;
loader.y = Ypos;
loader.alpha = 0;
addChildAt(loader,0);

```

}

var tween:Tween;  
function loadComplete(e:Event):void {  
for (var i:int=loaderA.length-2; i\>=0; i–) {  
tl[“tween\_”+i] = new Tween(loaderA\*, “alpha”, None.easeIn, loaderA\*.alpha, 0, 1, true);  
tl[“tween\_”+i].addEventListener(TweenEvent.MOTION\_FINISH,onMotio nFini sh);  
//  
}  
e.target.loader.contentLoaderInfo.removeEventListe ner(Event.COMPLETE, loadComplete);  
tween = new Tween(e.target.loader, “alpha”, None.easeIn, 0, 1, 1, true);  
}

function onMotionFinish(e:TweenEvent) {  
Loader(e.target.obj).unload();  
removeChild(e.target.obj);  
loaderA.splice(loaderAIndex(Loader(e.target.obj)), 1);  
e.target.obj = null;  
}

function loaderAIndex(loader:Loader):int{  
for(var i:int=0;i\<loaderA.length;i++){  
if(loaderA\*==loader){  
return i;  
}  
}  
return -1;  
}

/// Button Listerners  
one\_btn.addEventListener(MouseEvent.CLICK,btnClick );  
two\_btn.addEventListener(MouseEvent.CLICK,btnClick );  
three\_btn.addEventListener(MouseEvent.CLICK,btnCli ck);

btnA[0].dispatchEvent(new MouseEvent(MouseEvent.CLICK));
