thebackalleys

Main => General => Topic started by: ansel on April 7, 2009 03:36 AM

Title: ok this is pretty irritating
Post by: ansel on April 7, 2009 03:36 AM
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
Title: ok this is pretty irritating
Post by: RobHalford on April 7, 2009 03:54 AM
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();
}
Title: ok this is pretty irritating
Post by: rtil on April 7, 2009 03:54 AM
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
Title: ok this is pretty irritating
Post by: mrSimon on April 21, 2009 03:58 PM
[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
Title: ok this is pretty irritating
Post by: rtil on April 21, 2009 10:43 PM
oh my god
i haven't used cases since i learned VB 6 years ago
Title: ok this is pretty irritating
Post by: RobHalford on April 22, 2009 04:51 AM
I've always wanted to learn case/switch.