Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

load external swf and stop sound from previously loaded swf

Community Beginner ,
Feb 17, 2016 Feb 17, 2016

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);

}

TOPICS
ActionScript
436
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 17, 2016 Feb 17, 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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 17, 2016 Feb 17, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 17, 2016 Feb 17, 2016
LATEST

you're welcome.

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines