PDA

View Full Version : Why doesn't this work? Simple script.



youwhat?
October 4th, 2008, 12:57 PM
The following code is to make the movie stop/start when i click 'btn1'.


btn1.addEventListener(MouseEvent.CLICK, clicked)

function clicked (event:Event)

{
var stopped:int
trace(stopped)
if(stopped==0)

{
stopped=1
this.stop()
}

else

{
stopped=0
this.play()
}
}

The movie stops when i click it, but never resumes. Also the trace always shows 'stopped' as 0. Any help would be appreciated.

Smee
October 4th, 2008, 01:08 PM
You are declaring the variable every time the button is clicked, so it's always stopping. You need to declare it outside of the function for it to be stored.


var stopped:Boolean = false;

btn1.addEventListener(MouseEvent.CLICK, clicked);

function clicked(event:MouseEvent)
{
if(stopped)
{
stopped = false;
this.play();
}
else
{
stopped = true;
this.stop()
}
}