A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Stopping sound from _root and before it loops

  1. #1

    Stopping sound from _root and before it loops

    I have two problems I'm facing with sound. Just a note, this sound is linked as an actionscript.

    1. I have a sound that starts to loop in the main (root) index.swf
    file. The sound will continue to loop until a button is pressed
    to call the next MC. Therefore, I want the sound to stop when a
    MC is loaded. This is what I have inserted in the calling MC but
    it doesnt work. Am I missing something or syntax is incorrect?

    _root.firstSong.stop("index.swf", "Twilight Loop");


    2. When the user hits a button link from the navigation, I want
    this sound, "Twilight Loop" to stop at the moment it loops
    again. Below is the looping code, how do I set a time to
    stop it at the last frame before it begins to loop?

    firstSong = new Sound();
    firstSong.attachSound("Twilight Loop");
    firstSong.start(0, 99999); //0 offset with 99999 loops


    thanks

  2. #2
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    _root.firstSong.stop("index.swf", "Twilight Loop");

    should be:

    yourSoundObjectName.stop();

    Use an onEnterFrame loop to determine if the movie is loaded by checking if getBytesLoaded() == getBytesTotal() then call the stop() method as above.

    The second issue is awkward. Perhaps you can try to loop the sound with onSoundComplete(). Set a variable to true when the user clicks the desired navigation button and use an if/then statement in the onSoundComplete to determine whether the sound should loop again.

    ex.
    Code:
    mysound = new Sound(this);
    mysound.attachSound("some linkage ID");
    navbuttonclick = false;
    
    function checkToLoop(){
       // check if nav button pressed
       if(navbuttonclick == true){
          mysound.onSoundComplete = null; // stop sound loop
       } else {
          mysound.start(); // restart sound
       }
    }
    
    mysound.onSoundComplete = checkToLoop;

  3. #3
    thanks for the reply and help!

    I've placed in the MC file that is a level 2, yourSoundObjectName.stop(); and changed to firstSong.stop(); and it didnt work. So I added _level0 this worked for me to stop the root song: _level0.firstSong.stop();

    Now why wouldn't the loop song start playing in the loaded MC? Here is what I have thus far:

    _level0.firstSong.stop();
    secondSong = new Sound();
    secondSong.attachSound("Twilight Piano");
    secondSong.start(0, 99999); //0 offset with 99999 loops

    I'm still playing with the second issue of code you gave me...

    thanks.

  4. #4
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    secondSong = new Sound();

    always associate your sound objects with a unique movie clip instance name.

    secondSong = new Sound(target path to unique mc in same SWF as linked sound);

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