A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: How to stop sound

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    9

    Question How to stop sound

    Hello everyone.

    I'm in the making of a beginner project. Small picture button that shows a bigger picture after click. I want them play different sound before and after click. First small picture i placed in 1st frame and second picture i placed in 5th frame to jump in after click. Jumping works.

    Now the sound. I added mp3 sound to the first frame and it starts playing. Good.
    Then i added another sound to the 5th frame and here is the problem. After jump to the 5th frame both sounds are playing.

    I want to make 1st sound stops while jumping to the 5th frame and play second sound.

    How to make it?

  2. #2
    Junior Member
    Join Date
    Apr 2012
    Location
    Australia
    Posts
    21
    I think you might need to give us a little bit more info on how you are loading your sounds.

    Are you placing the sounds on the timeline, or creating them dynamically with ActionScript 3.0?

    If you're doing it dynamically, here's a good site to help you out. It goes through the basics of adding a SoundChannel (which is required for stopping particular sounds) and how to stop a sound: http://www.republicofcode.com/tutorials/flash/as3sound/

    Section "4. Stopping a Sound" on that page is probably what you're looking for. The code that does it (taken from the link above) is below:

    Code:
    var mySound:Sound = new Sound();
    var myChannel:SoundChannel = new SoundChannel();
    mySound.load(new URLRequest("myFavSong.mp3"));
    myChannel = mySound.play();
    
    stop_btn.addEventListener(MouseEvent.CLICK, onClickStop);
    
    function onClickStop(e:MouseEvent):void{
    myChannel.stop();
    }
    Hope that helps.

  3. #3
    Member
    Join Date
    Feb 2012
    Location
    Cairns - Great Barrier Reef - Australia
    Posts
    86
    Heres a good basic youtube example dude.. a basic jukebox playing 4 song files across 9 frames... not exactly what your after, but with a little thought it has all the elements you need for your project!.. But brace yourself, not as easy as you hoped!.. lol... made in as1 & 2...

    http://www.youtube.com/

    Luck!.. : )
    Defy the boundaries!.. NEVER surrender to the code!!!.....

  4. #4
    Junior Member
    Join Date
    Apr 2012
    Posts
    9
    Quote Originally Posted by Back2012 View Post
    Heres a good basic youtube example dude.. a basic jukebox playing 4 song files across 9 frames... not exactly what your after, but with a little thought it has all the elements you need for your project!.. But brace yourself, not as easy as you hoped!.. lol... made in as1 & 2...

    http://www.youtube.com/

    Luck!.. : )
    It was helpful, thanks.

    You too Danny. I suppose dynamic method is more flexible. Well as a beginner i'll stick to the timeline for now.

    Thanks again both of you.

  5. #5
    Dignitary rynoe's Avatar
    Join Date
    Jan 2003
    Location
    Earth
    Posts
    760
    There are many different ways to skin a cat here is an example of a slightly more bloodier version:

    Code:
    var mySound:Sound = new MySound();
    var mySoundCHNL:SoundChannel = new SoundChannel();
    mySound= mySound.play(0,1000);
    var mySoundVolume:SoundTransform = mySoundCHNL.soundTransform;
    mySoundVolume.volume = 0;
    volume can be set from 0 to 1.

    MySound is a sound file in the library as a class linkage
    [SIGPIC][/SIGPIC]

  6. #6
    Junior Member
    Join Date
    Apr 2012
    Location
    Australia
    Posts
    21
    Quote Originally Posted by rynoe View Post
    There are many different ways to skin a cat here is an example of a slightly more bloodier version:

    Code:
    var mySound:Sound = new MySound();
    var mySoundCHNL:SoundChannel = new SoundChannel();
    mySound= mySound.play(0,1000);
    var mySoundVolume:SoundTransform = mySoundCHNL.soundTransform;
    mySoundVolume.volume = 0;
    volume can be set from 0 to 1.

    MySound is a sound file in the library as a class linkage
    This is also another option, but the only issue is that the sound would still be "playing", just you can't hear it. This could be useful in some instances (where you can to have the sound continue playing as it will only be off for a while, like during a menu), but if you want to be optimal, it's probably best practice to stop the sound completely rather than mute it. All depends on the situation, really, but good job pointing this out, I forgot about it and it could help out a few others.

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