A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [HELP] Volume control and sound objects

  1. #1

    [HELP] Volume control and sound objects

    Hi, sorry if that question has been asked many times. But I still don't get it
    I'm creating a game and all the music worked fine until I noticed something:
    if I tell the music to fade out, all the sounds are affected (so I have no sounds if I have no music). I have read some tutorials and the Faqs here (Faq#4 i think) and it seems I have to attach the sound to a movie clip:
    Code:
    myMusic = new Sound(target path to unique mc);
    Now when I want to fade in and out, does the code have to be inside that clip? I'm very new with all the myMusic.attachSound("musicName"); stuff.. This is the code i made for fade in (fade out is quite similar but opposite) on a mc in the _root. timeline:
    Code:
    onClipEvent (enterFrame) {
    i = 5;
    
    if (fade == "in")
    {
    if(_root.volumeValue < 50)
    {_root.volumeValue += i;}
    else if(_root.volumeValue >= 50)
    {_root.volumeValue = 50;}
    }
    
    _root.myMusic.setVolume(_root.volumeValue);
    
    }
    I have tried many things but not the right one I guess.. Can someone help me with that?

  2. #2
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    have you associated the sound object with a movie clip?

    if not, then one simple way to do this is to make an empy mc, put it on the stage give it an instance name then use this instance name in the Sound() function.

    You can also dynamically create the movie clip, instead of manually placing it on the stage.

    // this code generates a movie clip named snd, attached to the current timeline and associates the mc with the sound object.
    myMusic = new Sound(createEmptyMovieClip("snd",getNextHighestDep th()));

  3. #3
    Quote Originally Posted by hp3
    have you associated the sound object with a movie clip?

    if not, then one simple way to do this is to make an empy mc, put it on the stage give it an instance name then use this instance name in the Sound() function.

    You can also dynamically create the movie clip, instead of manually placing it on the stage.

    // this code generates a movie clip named snd, attached to the current timeline and associates the mc with the sound object.
    myMusic = new Sound(createEmptyMovieClip("snd",getNextHighestDep th()));
    Ok, I have put:

    myMusic = new Sound(_root.musicMC);
    myMusic.attachSound("Mus_intro");

    Can you tell me what it does? Like if I want to control the volume, do I write:
    _root.musicMC.myMusic.setVolume(_root.volumeValue)
    or
    _root.myMusic.setVolume(_root.volumeValue);

    How do I locate this specific music now that it is associated with a movieclip?
    Last edited by SnailsAnimation; 02-08-2007 at 12:05 PM.

  4. #4
    Quote Originally Posted by SnailsAnimation
    How do I locate this specific music now that it is associated with a movieclip?
    Alright i think it works now,
    _root.musicMC.myMusic.setVolume(_root.volumeValue) ; doesn't work.
    So I use
    _root.myMusic.setVolume(_root.volumeValue);

    I think my problem was that the movieclip associated with the music wasn't "on top" and in every scene. So what I did was create an empty movie clip, gave it the instance "musicMC", put in in the beginning of my game (before the music starts) and insert:

    onClipEvent (load)
    {
    this.swapDepths(101); //just to make sure it's on top of everything
    }

    Now when my fade in and fade out codes are in use, it somehow detects that my music is located in this empty MC I created earlier. And the other sounds are not affected. What's great is that once a music finished playing, I can reuse the same empty MC to attach new musics.

    Thank you! You're the one who made me think about swapDepths, I did basicly the same thing you said exept I made the empty mc myself like a n00b

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