ok this is pretty irritating

Started by ansel, April 7, 2009 03:36 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ansel

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

Quote from: Factoryshut up you skinny white ugly prick

RobHalford

#1
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();
}

QuoteBut nevvgrounds is totally different from 4chan. We are a different set of people.
Quote<+ukinojoe> kirbopher is a pile of jackets
<+ukinojoe> if you remove them all
<+ukinojoe> all thats left is a dead rat

rtil

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

mrSimon

#3
[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

rtil

oh my god
i haven't used cases since i learned VB 6 years ago

RobHalford

I've always wanted to learn case/switch.

QuoteBut nevvgrounds is totally different from 4chan. We are a different set of people.
Quote<+ukinojoe> kirbopher is a pile of jackets
<+ukinojoe> if you remove them all
<+ukinojoe> all thats left is a dead rat