Avatar of joanna_l
joanna_l
 asked on

unload Movie in AS3

Hello!

   Is there any easy way of unloading an external movie that you have loaded into a flash file? I'm trying to create a website and whenever I click on a different button on my site, the externally loaded movie clip from the previous button still remains. Any ideas?

Many thanks!!
Adobe Flash

Avatar of undefined
Last Comment
kishoregp

8/22/2022 - Mon
kishoregp

use this
removeChild("loaded_mc");
joanna_l

ASKER
Hi kishoregp - thanks for getting back to me!

My code is...

How do I add the removeChild script so that it will clear the swf when another button is pushed?

Thanks!

Home.addEventListener(MouseEvent.CLICK, clickHome);
function clickHome(event:Event):void {
	gotoAndStop("Home");
}
 
portfolio.addEventListener(MouseEvent.CLICK, clickPortfolio);
function clickPortfolio(event:Event):void {
	gotoAndStop("Portfolio");
	var req:URLRequest = new URLRequest ("portfolio1.swf");
	var loader:Loader = new Loader ();
	loader.load(req);
	addChild(loader);
	loader.y = 200;
	loader.x = 150;
	loader.scaleX = .88;
	loader.scaleY = .88;
	}
 
CV.addEventListener(MouseEvent.CLICK, clickCV);
function clickCV(event:Event):void {
	gotoAndStop("CV");
}
 
Contact.addEventListener(MouseEvent.CLICK, clickContact);
function clickContact(event:Event):void {
	gotoAndStop("Contact");
}

Open in new window

kishoregp

first get your loader variable out
var loader:Loader = new Loader()
function clickPortfolio(ev....
.....
}

then in all your functions where you are leaving the frame, add removechild
function clickHome(event:Event):void {
removeChild(loader);
      gotoAndStop("Home");
}
similarly for childCV and clickContact
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
joanna_l

ASKER
Hi again....thanks again for your help (very very appreciated)!

  I've done what you suggested and now I'm getting this error when ever I click on the buttons :

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
      at flash.display::DisplayObjectContainer/removeChild()
      at website9_fla::MainTimeline/clickContact()
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
      at flash.display::DisplayObjectContainer/removeChild()
      at website9_fla::MainTimeline/clickCV()



var loader:Loader = new Loader ();
 
Home.addEventListener(MouseEvent.CLICK, clickHome);
function clickHome(event:Event):void {
removeChild(loader);
      gotoAndStop("Home");
}
 
portfolio.addEventListener(MouseEvent.CLICK, clickPortfolio);
function clickPortfolio(event:Event):void {
	gotoAndStop("Portfolio");
	var req:URLRequest = new URLRequest ("portfolio1.swf");
	loader.load(req);
	stage.addChild(loader);
	loader.y = 200;
	loader.x = 150;
	loader.scaleX = .88;
	loader.scaleY = .88;
	
}
 
 
CV.addEventListener(MouseEvent.CLICK, clickCV);
function clickCV(event:Event):void {
	removeChild(loader);
	gotoAndStop("CV");
	
}
 
Contact.addEventListener(MouseEvent.CLICK, clickContact);
function clickContact(event:Event):void {
	removeChild(loader);
	gotoAndStop("Contact");
	
}

Open in new window

ASKER CERTIFIED SOLUTION
kishoregp

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.