Pausing playback of a movieclip

  • the_Maven
  • Graduate
  • Graduate
  • the_Maven
  • Posts: 196

Post 3+ Months Ago

Hey,

I'm trying to make a pause/play button. I have a movie clip named 'loader'. here is the script i am trying - it's attached to the button.

on (release) {
var number;
number = 0;
if (number = 0) {
loader.stop();
number = 1;
} else {
loader.play();
number=0;
}
}

I checked the script for errors, and there aren't any, but when i test it in the .swf file, it doesn't work. Can any one help?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

It's because you are resetting the number variable to 0 every time you click the button.
  • the_Maven
  • Graduate
  • Graduate
  • the_Maven
  • Posts: 196

Post 3+ Months Ago


Thanks, i see what you are saying ... would this work then?

on (release) {
var number;
number = 1;
if (number = 0) {
loader.stop();
number = 1;
} else {
loader.play();
number=0;
}
}
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

No, because now you are always setting the number variable to 1 when you release the button. Don't give it a default value at all, let the if statement do that. Since Flash considers 0 as false and 1 as true in an if statement if the variable as no set value it will automatically be determined as false.

Also I just noticed another problem I didn't catch before (might I add... your text is too dark to read well, I recommend changing it) is that you are checking the value of number wrong. When comparing the value of one thing to the value of another you use "==", using just "=" is to set the value of a variable to something.

== is to compare

= is to set

So it would be if(number == 0)

And last put not least, since 0 and 1 are false and true (respectively) you can use the shorter method where just using the variable name checks if it is true and using the variable name prefixed by a "!" means it is false...

variableName = true
!variableName = false

So with that said... try something like this...
Code: [ Select ]
on (release){
//if the paused variable is false or non-existant
if (!paused){
 //stop the movie
 loader.stop();
 //set paused variable to true
 paused = true;
} else {
 //else if paused variable is true
 //play movie
 loader.play();
 //set paused variable to false
 paused = false;
}
}
  1. on (release){
  2. //if the paused variable is false or non-existant
  3. if (!paused){
  4.  //stop the movie
  5.  loader.stop();
  6.  //set paused variable to true
  7.  paused = true;
  8. } else {
  9.  //else if paused variable is true
  10.  //play movie
  11.  loader.play();
  12.  //set paused variable to false
  13.  paused = false;
  14. }
  15. }



I used "paused" as the variable name for two reasons... first it makes sense given the situation you are in... and the second is to prevent confusing flash with the Number() command (although I doubt it would, but better safe than sorry, you shouldn't really ever use preset flash commands as variable names)

And I also used true and false over 0 and 1 because to me it is just easier to read that way.
  • the_Maven
  • Graduate
  • Graduate
  • the_Maven
  • Posts: 196

Post 3+ Months Ago

Hey,
Thanks for the help there. I hope this color is more legible ... I didn't realize that there was a Number() command in AS. As you may have realized, i recently started trying to program with flash.

-The Maven
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

No problem. Your text is definitely much easier to read now, thank you for changing it.

And I understand you don't know the Number() command, and you are just learning, just giving you pointers to watch out for in the future and in your journey while learning :)

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 15 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.