View Full Version : Controlling a song in a movie
dominick100
02-27-2002, 02:53 PM
I have a hopefully simple question.
I'm trying to create a movie in which (among other things)clicking a button will play a song. Sounded easy, but I've hit some snags.
If I set up the song in a movie clip, and put an action on a button to play the clip, it works, but if I click the button 5 times, it plays the song 5 times, and sounds like garbage.
I tried using 2 buttons (loadmovie & unloadmovie) to load a seperate .swf containing only the song, and this worked, but I plan on converting the completed movie into a screensaver, and there's not any way to bring the other movie along with it (since I used the loadmovie command, and there will be no movie to load onve it's a .scr file)
I guess what I'm looking for is actionscript that (if someone clicks the "play" button more that once) will tell the song to NOT play again if it is already playing, but I have no idea how to do this. The limited resources I have as of right now (1 Book and a less-than-thorough DigitalThink CBT) have been no help.
I realize this is something I could probably learn with a new intermediate actionscript book, but I would really appreciate any help.
Thanks, Lou
on(release){
/*if the variable on the root level (notPlaying) is true,
then set it to false and play the sound...
next time button is clicked, the sound will not replay, cause
the var notPlaying is no longer true. set notPlaying to
true when the sound is done playing or turned off.
*/
if(_root.notPlaying){
_root.notPlaying=false;
_root.mySound.play();
}
}
dominick100
02-27-2002, 04:45 PM
OK, I tried this, and I'm still having trouble. I know something simple is eluding me, but I'm starting to get frustrated. I'll start from the beginning
I'm trying this with a simple test movie. I have:
-a start button-
-a stop button
-movie clip of a song with a stop action on the first frame, and the song beginning on the 2nd frame.
My 2 buttons are on the main timeline in the first frame. the movie is only 1 frame long.
on the 1st frame, I've set the action: notplaying= true
On the start button, I placed the actions:
on (release) {
if (notplaying= true) {
notplaying = false;
with (_root.song) {
gotoAndPlay (2);
}
}
}
On the stop button, and at the end of the song in the movie clip, I placed the setvariable "notplaying=true"
What am I doing wrong here? If I test the movie and show variables, it shows Variable _level0.notplaying = true, but it never changes. Do I need the "_root." in front of the variable? I tried it this way as well, and it didn't make a difference.
Arghh.
i don't use sound too often, but you may do some searching on the forum here to find info on the sound object. and use sound.start,sound.stop
for the var, initialize the notPlaying var to true on the main timeline in the first frame.
a test i did worked on my machine, the way your trying to do it. altho i don't know how you will stop it without either using the sound object for your sound or telling the song mc to gotoAndStop("lastframe") (where last frame is a labeled frame in your mc.
dominick100
02-27-2002, 06:48 PM
I did set the variable notplaying to "true" on the 1st frame. In testing the movies, that's the only variable that ever shows when I do "show variables".
I will stop the sound with the "stop" button using "stopallsound". I don't really care if it loops, though. my main issue is making sure that if you push the "start" button 5 times, one second apart, it doesn't play the song 5 times, overlapping itself. That would pretty much wreck the song.
Would it be possible for you to post the test you did that worked? There may be something simple I'm missing.
Thanks.
farafiro
02-28-2002, 09:39 AM
okey dominick100 try this:
- two Buttons on the screen [start / stop]
- your song on the library has been instaniated (right click > linkage > Export sympol as> "choose whatever name u want, I put mySong here")
CODE for the buttons :
start button
on(press, release){
mySound = new Sound
mySound.attachSound("mySong")// dont 4get the ""
mySound.start(0,1)// 0 is for the delay u want before starting your song & 1 is the number of loops you want the song to be repeated so 1 means that it will play one time, 2 means twice ....
}
stop button
on(press, release, releaseOutside){
mySound.Stop()
}
dominick100
02-28-2002, 11:01 AM
I appreciate the new way to start a sound (I did not know that technique), but I'm still having the same problem.
If I click the "start" button twice, the song plays twice, overlapping, and this wrecks it.
In doing some research, I think I need to use SetVariable, but I can't make it work.
On the 1st frame (and only frame) of the movie, I have the setvariable playing = false.
On the start button, I have ....
if playing = false,
with (instance of movieclip containing song)
goto and play 2 (I have a stop action on the first frame of the clip, and the song begions on the 2nd)
Then, on the 2nd frame of the movie clip, I have the action set playing = true, and on the last frame set playing = false.
My hope with this, is that as long as the song is playing, it cannot play again until it is done.
I also tried putting set playing = true on the start button, but this didn't work either.
Does anyone have a clue of what I'm doing wrong? Don't take any possible mistake on my part for granted, no matter how obvious it may seem. I could be screwing this up at any point in the process. I really don't have much experiance with setting variables.
Thanks.
farafiro
02-28-2002, 12:36 PM
Here it is:
http://www.geocities.com/a_fayek/dominick.zip
dominick100
02-28-2002, 01:57 PM
OHMIGOD THAT DID IT.
I can already feel my headache dissolving.
I wasn't handling the variables correctly, but I think I get it now. Thanks for the exposure to attachsound, too.
I'm going to buy an exclusively-actionscript book this weekend.
Thanks again!
farafiro
02-28-2002, 02:02 PM
:D :D :D :D
What Book u r gonna buy
dominick100
02-28-2002, 02:17 PM
Just from looking at the reviews on Amazon, I was either going to get "Actionscript: THe Definitive Guide" by Moock or "ActionScripting in Flash" by Kerman.
I was also looking at "Foundation Actionscript" by Sham Bhangal. The reviews were pretty mixed, but a few said it was written more from the designer perspective, rather than the programmer. Since I have a little design experience, but very little in programming, I thought that might be helpful.
buy them through the link on this site. daddy wants a new server.
farafiro
03-03-2002, 05:32 AM
Originally posted by tg
buy them through the link on this site. daddy wants a new server.
Heheheheheeeeeeee, Oh daddy I also want some candies
andy@sg
06-17-2002, 03:51 PM
Originally posted by farafiro
Here it is:
http://www.geocities.com/a_fayek/dominick.zip
Hi farafiro, would you mind posting this zip file again?
farafiro
06-18-2002, 06:38 AM
Hmmmmmmmmmmmmmm, who is that guy that waking me up after all that time sleeping
heheheheeeeeeeeeeeee
I didn't remove it man
farafiro
06-18-2002, 06:41 AM
Oooops, sorry
here
http://www.geocities.com/a_fayek/flash/dominick.zip
andy@sg
06-18-2002, 11:05 AM
sorry fariro,
the page not available...hehehe :confused:
farafiro
06-18-2002, 11:08 AM
nop it's but the bad geocities links
just write it in the address tab without the name of the file
http://www.geocities.com/a_fayek/flash
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.