dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [F8] Looping and stopping Sounds

  1. #1
    Senior Member
    Join Date
    Apr 2001
    Posts
    175

    [RESOLVED] Looping and stopping Sounds

    In my game I want to use looping sounds for machine gun fire. Both the main player and the AI might be firing, so all the sounds need to be controlled separately - I need to be able to stop one without stopping the rest. I understand that the way to do this is to make each sound on a different MovieClip (so if I want to control sound1 and sound2 separately, I do sound1=new Sound(mc), sound2=new Sound(different_mc). But while this works fine for movie clips that I drag and drop onto the stage, it doesn't seem to work with MCs I create using attachMovie or createEmptyMovieClip. Why does this happen, and is there an elegant way around it?

    Thanks very much,
    Max
    Last edited by Flecko; 07-16-2006 at 04:06 PM.

  2. #2
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    this.createEmptyMovieClip("sound1",100);
    this.createEmptyMovieClip("sound2",110);
    s1 = new Sound(sound1);
    s2 = new Sound(sound2);
    s1.attachSound("s1_librarySound");
    s2.attachSound("s2_librarySound");

    s1_librarySound and the same for s2_librarySound are sounds that you have previously imported into the library and set the linkage identifiers to these names (or whatever names you want)
    you then start the sound with
    s1.start();

  3. #3
    Senior Member
    Join Date
    Apr 2001
    Posts
    175
    Yeah, so I got that working...it's real weird, if I make two sounds on separate movie clips in one place in my code, it's all good, I can start and stop them independently. But when I have each of the weapons make their own sound, and soon as one stops firing, they all do. It's driving me nuts, but I guess the problem probably doesn't have to do with the Sound class directly...

  4. #4
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    how are you stopping the sounds?

  5. #5
    Senior Member
    Join Date
    Apr 2001
    Posts
    175
    mysound.stop()

    I can't do it with the linkage name because there might be multiple instances of the same type of gun using the same sound but only one is supposed to stop firing

  6. #6
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    sorry not sure what the problem is- try posting it in the sounds forum

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