A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: loading sound inside a container

  1. #1
    Member
    Join Date
    Jul 2009
    Posts
    69

    loading sound inside a container

    I have a simple question that I'm nevertheless struggling with.

    I'm doing frame by frame animation and have different sounds playing upon activation of different functions (not button based) both within the same frame as well as in the other frames (hope that makes sense).

    Anyway, all I've done previously is set up background sounds for the whole doc, so I'm used to doing this:

    var mySoundReq:URLRequest = new URLRequest("mySound.mp3");
    var mySound:Sound = new Sound();
    mySound.load(mySoundReq);

    mySound.play();

    Given my current needs, this doesn't work. Sure, the sound plays, but then it plays again in the next frame when a totally different sound should be playing (the two sounds overlap each other). Obviously this is because I'm not removing the sound that was loaded on the first frame. I'm thinking I should place the sound inside a container and then be able to "empty" that container (removeChild?) at the end of the code in frame 1 (or very beginning of frame 2), and thus allowing me to add the second sound to that container in frame 2. Again, hope I'm making sense.

    I'm stuck on how to do this though. Do I ..

    1) define a movieclip var, then place the mySound into it --mc.addChild(mySound)--, then load the URLReq onto the mc -- mc.load(mySoundReq)??

    2) define mc var, load the URLReq onto the already define mySound var, then mc.addChild(mySound) ? To remove later on, is it as simple as mc.removeChild(mySound) ... and just mc.addChild(nextSound).

    Or should I be setting up a SoundChannel here? (I've seen it work on button-based controls of sounds, but not any other way, so a little thrown).

    TIA to any nudge in the right direction.
    Last edited by Leftyplayer; 10-01-2009 at 01:12 PM.

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