Skip to main content
February 28, 2009
Question

changing between swf files

  • February 28, 2009
  • 6 replies
  • 385 views
Here is the code that I am using to call files for a swf movie changer example I am putting together:

I need to find out how to stop the sound of one swf file when a button is pressed to play another movie.

currently when I play the other movie when one is already playing, the old cllip sound doesn't stop.

Also need to know how to control the volume on an swf file which is playing.

Any help would be greatly appreciated. Thanks
This topic has been closed for replies.

6 replies

kglad
Community Expert
Community Expert
March 6, 2009
no import statement is needed.

but you can't set the soundTransform property of the loaded content unload loading is complete.
March 6, 2009
revised code is this without the import statement:

var imageRequest1:URLRequest = new URLRequest('location of first file which is remote url');
var imageRequest2:URLRequest = new URLRequest('location of second file which is remote url'');
var imageLoader:Loader = new Loader();
addChild(imageLoader);


video_mc.buttonMode = true;
/*video_mc.addEventListener(MouseEvent.MOUSE_OVER,hoverMouse);
video_mc.addEventListener(MouseEvent.MOUSE_OUT,leaveMouse);*/
video_mc.addEventListener(MouseEvent.CLICK,getMovie1);

video2_mc.buttonMode = true;
/*video2_mc.addEventListener(MouseEvent.MOUSE_OVER,hoverMouse);
video2_mc.addEventListener(MouseEvent.MOUSE_OUT,leaveMouse);*/
video2_mc.addEventListener(MouseEvent.CLICK,getMovie2);

//this is the sound transform section ... is it in the right place and is an import statement needed?
var st:SoundTransform=new SoundTransform();
st.volume = 0.5;
MovieClip(imageLoader.content).soundTransform=st;


function hoverMouse(e:Event):void{
e.currentTarget.gotoAndStop("over");
}
function leaveMouse(e:Event):void{
e.currentTarget.gotoAndStop("out");
}
function getMovie1(e:Event):void {
SoundMixer.stopAll();
imageLoader.unload();
imageLoader.load(imageRequest1);
imageLoader.x = 30;
imageLoader.y = 30;
}

function getMovie2(e:Event):void {
SoundMixer.stopAll();
imageLoader.unload();
imageLoader.load(imageRequest2);
imageLoader.x = 10;
imageLoader.y = 80;
}
March 6, 2009
ok I have tested the file locally and it works fine,, but when I test the file online it actually doesn't work correctly....

I am using the code you gave me on :

SoundMixer.StopAll();

the code is like follows:

function getMovie1(e:Event):void {
SoundMixer.stopAll();
imageLoader.unload();
imageLoader.load(imageRequest1);
imageLoader.x = 30;
imageLoader.y = 30;
}

and the other function to play the other movie is the same.

also when I tried to adjust the volume like you said,,, It gave me an error:

typeError: Error #1009: cannot acces a property or method of a null object reference.

I put a value of 0.5 to the volume attribute and have it outside the functions. This should make the inported swf's half the volume of what they are originally no matter which button you press, correct? should i have a import statement for the SoundTransoform class? I tried to make an import statement, but it gave me errors saying SoundTransform could not be found.
kglad
Community Expert
Community Expert
March 4, 2009
you're welcome.
March 4, 2009
so if the sound is part of the imported swf clip this would work? I will try this and let you know what i come up with.. ty
kglad
Community Expert
Community Expert
March 1, 2009
if the sound is attached to the timeline, you can use the soundTransform property of your loader's content (cast as a movieclip):

var st:SoundTransform=new SoundTransform();
st.volume = whatever;
MovieClip(imageLoader.content).soundTransform=st;

if you create the sound dynamically, create a soundChannel instance what you start your sound:

var st:SoundTransform=new SoundTransform();
st.volume = whatever;
MovieClip(imageLoader.content).sc.soundTransform=st;

and you can always use SoundMixer.stopAll() to stop all sounds.