Actionscript has a habit of not working, even when it's dealing with the simplest things one could imagine. Here's my code, I'm trying to make a pause/play button. playinga is set to 1 when the movie begins.
[codebox]on (press) {
if (_root.playinga == 2) {
_root.playinga = 1;
_root.play();
}
if (_root.playinga == 1) {
_root.playinga = 2;
_root.stop();
}
}
[/codebox]
Now pausing the movie works just fine. I can pause at any point and playinga will dutifully change to 2 and the movie will stop playing. It's starting it again that's the problem. playinga stays at the value of 2 and my movie stays paused. WHYYYYYYY
AS3
playbtn.visible = false;
pausebtn.addEventListener(MouseEvent.CLICK, pauseClick);
function pauseClick (evt:MouseEvent):void{
playbtn.visible = true;
pausebtn.visible = false;
stop();
}
playbtn.addEventListener(MouseEvent.CLICK, playClick);
function playClick (evt:MouseEvent):void{
playbtn.visible = false;
pausebtn.visible = true;
play();
}
the actionscript is working just fine. when playinga = 2, it sets it to 1, then reads the next if statement, consequently changing it back to 2 and not doing anything. you need to nest the if statements to solve this
[codebox]on (press) {
if (_root.playinga == 2) {
_root.playinga = 1;
_root.play();
} else if (_root.playinga == 1) {
_root.playinga = 2;
_root.stop();
}
}[/codebox]
Fixed. >=( You forgot else, so now it'll only process the second if test if the first returns as not true (IE FALSE! )
If you wanted to get fancy, you could do this...
[codebox]on (press) {
switch (_root.playinga){
case 2:
_root.playinga = 1;
_root.play();
break;
case 1:
default:
_root.playinga = 2;
_root.stop();
break;
}
}[/codebox]
Its up to you
oh my god
i haven't used cases since i learned VB 6 years ago
I've always wanted to learn case/switch.