-
Pause/Play Toggle Button?
I have an AIF file I created in Garage Band. This AIF has been placed into a movie clip called "mymusic" that has been placed on a layer in my movie with an instance name of "mymusic."
I have created play button and pause buttons that utilize the following scripts to stop the sound and the movie and then resume the sound and movie from the point where it was stopped:
Play Button:
on (press) {
play();
tellTarget ("mymusic") {
play () ;
}
}
Stop Button:
on (press) {
stop();
tellTarget ("mymusic") {
stop () ;
}
}
This works perfectly. Now the client wants me to combine the play and pause button and create a single toggle button that achieves what the above two described buttons did.
Any thoughts? Please help!!!
-
Flashmatics
put this on your _root timeline:
Code:
var musicPaused:Boolean = true;
and then your button press should be:
Code:
on (press) {
if(!_root.musicPaused){
stop();
_root.musicPaused = true;
tellTarget ("mymusic") {stop ();}
}else{
play();
_root.musicPaused = false;
tellTarget ("mymusic") {play ();}
}
}
P.S why are you using tellTarget? that has been deprecated a long time ago... u should use dot notation instead
-
Silentweed,
Thanks for the help. It doens't appear to be working though. My button still changes from the play to the pause icon and the music stops, but when I press the button again the music won't restart.
Any thoughts? I can attach the movie if you want.
Oh, and I'm using the yell Target script because I'm pretty much a Flash novice. Any better suggestions?
Thanks again!
-
I've been playing with the script a little and had added this to it:
on (press, release) {
if (!_root.musicPaused) {
stop();
_root.musicPaused = true;
tellTarget ("mymusic") {stop ();}
} else {
play();
_root.musicPaused = false;
tellTarget ("mymusic") {play ();}
}
}
on (release) {
if (_root.stop == 1) {
tellTarget (stop_play) {
gotoAndPlay(2);
}
} else {
//_root.play();
tellTarget ("mymusic") {
stop () ;
}tellTarget (stop_play) {
gotoAndPlay(1);
}
}
}
When I click the button the music will stop and the button state will change from pause to stop. However, only when I click and hold will the music resume playing. Also, if I completely eliminate the button swap portion of the script, the pause will work, but it only works the second time I click the button. The first click (even if I click and hold) will only cause the music to pause for half a second and then it resumes playing.
Any thoughts?
Thanks!
-
Flashmatics
hi, yeah it will be easier to understand if you upload your fla
-
Hey. I got it!
I had two extra lines of script in there that were messing it up and then I commented-out the "Boolean" script and that took care of it. Weird. Any thoughts on that? I wonder if it was conflicting with the antiquated "tellTarget" script.
Thank God I can design, because I'm not much of a programmer.
Thanks so much for your help!
Best of luck!
-
Specify you flash version. Maybe it's not 8... ?
gparis
-
-
the file is probably not set to support actionscript 2.0 in the publish properties to support:
var musicPaused:Boolean = true;
-
That whole script was written a long time ago, using at best Flash5. Or by someone who hasn't touched AS for years....
gparis
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|