A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Stopping a sound in a loaded swf

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Location
    Atlanta
    Posts
    103

    Stopping a sound in a loaded swf

    Is this possible? I've loaded an external swf into my movie - the swf stays on stage but loses focus throughout a users interaction.

    When it loses focus, I need the sounds within it to stop.

    It was mentioned that I should cast my swf as a movie clip but when I try I get errors.

    What's the best way to go about this?

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    How do you play your sound in the movie, do you load an external sound?
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Senior Member
    Join Date
    Apr 2002
    Location
    Atlanta
    Posts
    103
    Yes, I load external sounds in the swf that I load:

    Code:
    buzz = new Sound();
    buzz.load(new URLRequest("static.mp3"));
    buzz.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
    buzz.addEventListener(Event.COMPLETE, onLoadComplete, false, 0, true);
    	
    yell = new Sound();
    yell.load(new URLRequest("yell.mp3"));
    yell.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
    yell.addEventListener(Event.COMPLETE, onLoadComplete, false, 0, true);

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    In your child movie create a SoundChannel object:

    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLRequest;
    var channel:SoundChannel;
    var mySound:Sound = new Sound();
    mySound.load (new URLRequest("track2.mp3"));
    channel = mySound.play(0,1);

    In your parent movie you have this script. I made this for a button to stop the sound, so you need to modify. I left traces, so you can see what you get as output.

    var myLoader:Loader = new Loader();
    myLoader.contentLoaderInfo.addEventListener(Event. COMPLETE, onComplete);
    myLoader.load(new URLRequest("soundMovie.swf"));
    addChild(myLoader);
    var loadContent:Object;
    function onComplete(e:Event):void
    {
    loadContent = e.currentTarget.content;
    trace(loadContent);
    }
    but.addEventListener(MouseEvent.CLICK, ch);
    function ch(e:Event):void
    {
    trace(loadContent.channel);
    loadContent.channel.stop();
    }
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  5. #5
    Senior Member
    Join Date
    Apr 2002
    Location
    Atlanta
    Posts
    103
    Thanks for this tip cancerinform, will be working with your example momentarily!~

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