Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
Many thanks. Code works, My students will enjoy the improved functionality.
Copy link to clipboard
Copied
you're welcome.
(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now