-
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?
-
Senior Member
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. -
-
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);
-
Senior Member
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. -
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|