Skip to main content
Participating Frequently
February 18, 2016
Question

load external swf and stop sound from previously loaded swf

  • February 18, 2016
  • 1 reply
  • 477 views

Please excuse my potentially inelegant code.

I created a file that loads student animations via button click. They have sound and when the new swf loads the sound from the previous swf continues on top of the new

swf sound. I've tried solutions from various discussion threads but I am afraid my clumsy use of AS3 is impeding my efforts.  I welcome suggestions.

var myLoader:Loader = new Loader();

loadItem1_btn.addEventListener(MouseEvent.CLICK, loadPic1);

loadItem2_btn.addEventListener(MouseEvent.CLICK, loadPic2);

function loadPic1(MouseEvent):void {

var myRequest:URLRequest=new URLRequest("Alejandro.swf");

myLoader.load(myRequest);

myLoader.x=200;

myLoader.y=150;

addChild(myLoader);

}

function loadPic2(MouseEvent):void {

var myRequest:URLRequest=new URLRequest("Hayley.swf");

myLoader.load(myRequest);

myLoader.x=200;

myLoader.y=150;

addChild(myLoader);

}

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
February 18, 2016

assuming you use the same loader to load all the swfs:

var myLoader:Loader = new Loader();

loadItem1_btn.addEventListener(MouseEvent.CLICK, loadPic1);

loadItem2_btn.addEventListener(MouseEvent.CLICK, loadPic2);

function loadPic1(MouseEvent):void {

if(myLoader.content){

myLoader.unloadAndStop();

}

var myRequest:URLRequest=new URLRequest("Alejandro.swf");

myLoader.load(myRequest);

myLoader.x=200;

myLoader.y=150;

addChild(myLoader);

}

function loadPic2(MouseEvent):void {

var myRequest:URLRequest=new URLRequest("Hayley.swf");

myLoader.load(myRequest);

myLoader.x=200;

myLoader.y=150;

addChild(myLoader);

}

dateacherAuthor
Participating Frequently
February 18, 2016

Many thanks. Code works, My students will enjoy the improved functionality.

kglad
Community Expert
Community Expert
February 18, 2016

you're welcome.

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)