A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: PLAY sound and STOP sound

  1. #1
    Junior Member
    Join Date
    Apr 2002
    Posts
    21

    PLAY sound and STOP sound

    I have no clue how to play and stop sound. I tried everything but I guess I am doing it wrong!
    basically...... the name of the clip i want to play is
    sound1

    i have a little play button and a little stop button
    i need the code so that it will play sound1 when clicked on
    and the stop button i just put stop all sounds so i guess that should take care of it..but if that is wrong then please let me know, lol
    thanks

    xox marqi

  2. #2
    Member
    Join Date
    Oct 2002
    Location
    Los Angeles
    Posts
    77
    Depending on how large your sound file is one way to do it is to put the sound in its own movie clip (streaming instead of event)then control that clip with "tell target" instead of the just the sound..

    Then you wouldnt need to stop all sounds..just manipulate that clip with the sound on it..

    You could even resume the sound where you left off...

    If the sound is huge...Youd probably want someone else here to help you out with some action script..(attach sound functions and whatnot).

    Hope this helps
    -JB

  3. #3
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Hmmm, I'd like to know how to resume a sound where it left off.....

    You can also add the sound to the button timeline. Open the button timeline, add a new layer, make a keyframe on the newlayer under the down frame of the button. Drag the sound onto the stage. In Properties, in the 'Sync' box, set it to 'Start'.

  4. #4
    Junior Member
    Join Date
    Apr 2002
    Posts
    21

    still cant get it

    No...that is not what i was talking about lol
    i just need the code to put in the actions box
    the code to make the "play button" play the music
    and then the code to put on the stop button to stop the music

    whenever i do it its like play(o) or something like that....
    PLEASE HELP ME!

  5. #5
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Well, if you add the sound like I mentioned, you don't need any script, only the button instance. To stop sounds add to the stop button:

    on (release) {
    stopAllSounds();
    }

  6. #6
    Junior Member
    Join Date
    Apr 2002
    Posts
    21

    the button

    but dont i have to have a function on the button the play button?

  7. #7
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Nope, it's built into the down state of the button. When you press down, that tune is going to start and will play all the way through, unless you hit stop. The play button, has to be just for that play action. You can't use a copy of a button in the library, cause it adds the sound to all of them.

    If you want to load the sound, which has it's advantages, do it the way JBOMBER said. Make the sound a movie clip, and load the clip, or even make it a separate swf movie, and load that. There are a lot of ways, but the button way works and it's easy.

  8. #8
    Junior Member
    Join Date
    Apr 2002
    Posts
    21

    hui

    OK! this is not working at all.....can i have one of your email address's i will send you the file then maybe you might get what i am trying to do....let me know if your still interested in helping me....email me or reply here
    marqi143@yahoo.com

  9. #9
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    I just sent mail, reply with the attachment. Make sure the sound file is in the library.

  10. #10
    Moderator enpstudios's Avatar
    Join Date
    Jun 2001
    Location
    Tampa, Fl.
    Posts
    11,282
    Try this sound Object tute:

    www.kennybellew.com

  11. #11
    Junior Member
    Join Date
    Apr 2002
    Posts
    21

    ahhhh

    OK! yay i got the play button to work. but guess what???? NOW I CANT GET THE STOP button to work. ok....i made a preloader in the begining of the movie on the 1st scene now when ever i publish it the preloader gets stuck......i am seriously in a world of chaos! i now have like the updated file with all problems listed above...let me know who i can send this to so you can tell me what idid wrong cause i really want to figure this out!

  12. #12
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    There was a problem with the start and stop buttons. I finally had to delete them and pull out an instance of symbol 36 and 37 to remake them clean. I added the sound to the button timeline, like I said, and the action to the stop button, so your working now. I only looped the sound 5 times, you may want to set it higher. But it is in Flash 6 now. I never asked if you were using MX or not. F5 won't do it.

  13. #13
    Registered User
    Join Date
    May 2012
    Posts
    6
    Hi, I am new to this forum. I am busy building a flash site for a band but I am very new to sound in flash. I am using actionscript 2.

    What I want to do with their songs is when you click on the button the song starts playing (That part I can do), what I am having trouble with is if you click the button to play "song 1" (it starts playing) and then click the button to play "song 2", I want "song 1" to stop automatically. I don't want the user to have to click a stop button.

    I put the song into the song button's timeline as I am not very good with the coding in flash.

    Any help will be much appreciated.

  14. #14
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Hi and welcome,

    I put the song into the song button's timeline as I am not very good with the coding in flash.
    DON'T DO THAT, 'cause it's a very messy way of doing so. The are tons of tutorials on the internet regarding this matter, so a quick google search wouldn't have hurt.

    To accomplish this, you'll need greater control over your sounds, so coding would be an easy way out. To do this, presuming you already have a Sound file in your Library, find it there (in your Library, that is), right-click it, press Properties (or Linkage in Flash 8), expands Show Advanced, tick/check Export for ActionScript, and in the Identifier field, type in something like, sound1, and press OK. Repeat this for your second sound file, but give it a unique identifier name, like, sound2.

    Presuming that you have 2 buttons on your Stage, click on one of them, open Properties Panel [CTRL+F3], and in the textfield labeled Instance Name, type in something like, song1_btn. Repeat with the second button, but give it a unique Instance name, such as, song2_btn.

    Finally, select your Frame and open Actions Panel [F9], and type this:

    Actionscript Code:
    sound1 = new Sound();
    sound1.attachSound("sound1");

    sound2 = new Sound();
    sound2.attachSound("sound2");

    song1_btn.onPress = function(){
        sound1.start();
        sound2.stop();
    }

    song2_btn.onPress = function(){
        sound2.start();
        sound1.stop();
    }

    In the first 4 lines, we create 2 Sound objects, to control each sound individually, and attach the corresponding sounds to the Sound objects (in layman's terms, we assign sound1 and sound2 from the Library to the 2 variables, so that we can play/pause them whenever we want). Next, we make song1_btn and song2_btn do something when they are pressed, and in this case, for song1_btn, we start playing sound1 and stop sound2, but for song2_btn, we start playing sound2 and stop sound1.

    This may be really confusing for you, as I'm just throwing a lot of difficult code for a new beginner like you, but this is an easy outway to solve your problem. The more suitable way for you, but more time-consuming and messy, would be to add each sound in their own movieclips on the Timeline, either set the sound to Stream or use stopAllSounds() command to stop all sounds, and then control the timelines of the movieclips with the songs to play/stop them.

    Hope this helps, nonetheless
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  15. #15
    Registered User
    Join Date
    May 2012
    Posts
    6
    Quote Originally Posted by Nig 13 View Post
    Hi and welcome,



    DON'T DO THAT, 'cause it's a very messy way of doing so. The are tons of tutorials on the internet regarding this matter, so a quick google search wouldn't have hurt.

    To accomplish this, you'll need greater control over your sounds, so coding would be an easy way out. To do this, presuming you already have a Sound file in your Library, find it there (in your Library, that is), right-click it, press Properties (or Linkage in Flash 8), expands Show Advanced, tick/check Export for ActionScript, and in the Identifier field, type in something like, sound1, and press OK. Repeat this for your second sound file, but give it a unique identifier name, like, sound2.

    Presuming that you have 2 buttons on your Stage, click on one of them, open Properties Panel [CTRL+F3], and in the textfield labeled Instance Name, type in something like, song1_btn. Repeat with the second button, but give it a unique Instance name, such as, song2_btn.

    Finally, select your Frame and open Actions Panel [F9], and type this:

    Actionscript Code:
    sound1 = new Sound();
    sound1.attachSound("sound1");

    sound2 = new Sound();
    sound2.attachSound("sound2");

    song1_btn.onPress = function(){
        sound1.start();
        sound2.stop();
    }

    song2_btn.onPress = function(){
        sound2.start();
        sound1.stop();
    }

    In the first 4 lines, we create 2 Sound objects, to control each sound individually, and attach the corresponding sounds to the Sound objects (in layman's terms, we assign sound1 and sound2 from the Library to the 2 variables, so that we can play/pause them whenever we want). Next, we make song1_btn and song2_btn do something when they are pressed, and in this case, for song1_btn, we start playing sound1 and stop sound2, but for song2_btn, we start playing sound2 and stop sound1.

    This may be really confusing for you, as I'm just throwing a lot of difficult code for a new beginner like you, but this is an easy outway to solve your problem. The more suitable way for you, but more time-consuming and messy, would be to add each sound in their own movieclips on the Timeline, either set the sound to Stream or use stopAllSounds() command to stop all sounds, and then control the timelines of the movieclips with the songs to play/stop them.

    Hope this helps, nonetheless
    Thank you for your help. I will attempt to use the codes you have given me and try to fix my problem. If I still struggle I will let you know.

  16. #16
    Registered User
    Join Date
    May 2012
    Posts
    6
    Somewhere I am doing something very wrong as I cannot get it to work... I followed your guide step by step but somewhere I am missing something as the songs don't want to play.

    Just a couple of questions:
    1) Must the buttons be on the same layer? They were on different layers when I tried it the first time (it didn't work) so I moved them to the same layer (still doesn't work though).
    2) I tried the code in the frame (of the buttons) when I moved the buttons onto the same layer and I also tried it in the actions for the buttons themselves. (Yes, I am desperate to get this right).

    Any other help you can give me would be great as I need this to work.
    Last edited by IncomingVirus; 05-15-2012 at 08:28 AM.

  17. #17
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    The layer they're on doesn't count, and you don't apply the code to the buttons, but to the FRAMES

    Click on any Layer's Frame (preferably a frame with one of the buttons), press F9 to open Actions Panel, and then add the code I've provided. You are not applying the codes to the buttons themselves, but to the Frames.
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  18. #18
    Registered User
    Join Date
    May 2012
    Posts
    6
    I did, but it still does not work. There is no sound, the songs won't play at all. I am using CS4 Actionscript 2 if that helps at all but will be upgrading to CS5 soon.

  19. #19
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    You don't apply the code to a Frame inside the button, but on a Frame OUTSIDE both of the buttons on the main stage, if that still doesn't work, then would you mind posting your FLA File?
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  20. #20
    Registered User
    Join Date
    May 2012
    Posts
    6
    My file is way too big and even when I compress it I can't get it down to the allowed size for uploading as the size limit is 300kb and my file when compressed is 22mb.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center