Skip to main content
Participant
August 9, 2008
Question

Preventing external swfs loaded into a movieclip image from stacking

  • August 9, 2008
  • 2 replies
  • 378 views
So I've been building a webpage that contains 5 "content" sections each loaded on their own swf files into a movieclip called loader_mc when I click the corresponding button. So far, my code works to load the swf's into a movieclip entitled loader_mc when I click on the respective buttons but when I try to change sections, that's where things unravel.

The "samples" section streams video, and when I leave the "samples" section, the audio is still streaming even if I'm looking at the "about" page (or any of the other for that matter). It seems as if my swf's just keep loading one on top of another (not what I want), where what I want to accomplish is to have the swf files replaced upon clicking a button with whatever swf is appropriate to the section I've just clicked. That way dynamic content doesn't sound or appear to be playing even when the user is supposed to have made it "go away". Below I've pasted the code that I think you'll all need to see in hopes you may be able to assist me in tweaking my code to get it to operate.

Here's where I defined my variables:

var contentLoader:Loader = new Loader();
var aboutURL:String = "z_about.swf";
var aboutRequest:URLRequest = new URLRequest(aboutURL);
var samplesURL:String = "z_samples.swf";
var samplesRequest:URLRequest = new URLRequest(samplesURL);
var contactURL:String = "z_contact.swf";
var contactRequest:URLRequest = new URLRequest(contactURL);
var linksURL:String = "z_links.swf";
var linksRequest:URLRequest = new URLRequest(linksURL);
var homeURL:String = "z_home.swf";
var homeRequest:URLRequest = new URLRequest(homeURL);

And here's an example of one of my buttons codes for the Click event:

function linksClick(event:MouseEvent):void
{
zMenu.links_words.gotoAndPlay("click");
contentLoader.load(linksRequest);
loader_mc.addChild(contentLoader);
}

Does anyone have any idea where I might have gone wrong? I've made it this far mostly through tutorials, but I think I'm in a little over my head at combining the things I've picked up without forgetting important elements. Any help is greatly appreciated.
This topic has been closed for replies.

2 replies

kglad
Community Expert
Community Expert
August 10, 2008
other than the fact there's no reason to make your loader a child of load_mc, you must do what you're doing.

on the other hand, there's no harm in making your loader a child of load_mc, either.

but again:

to remove the loaded content from your application you must remove the loader from your application.

to do that your loader that must by removed from the display list (in your case by removing it from another display object (loader_mc) (which you did), all streams in the loader's content property must be stopped (which you didn't do) and all referernces to the loader (including listeners) must be removed (which you didn't do but i don't know if you need to do) and finally you must assign your loader to be null (which you didn't do).
kglad
Community Expert
Community Expert
August 9, 2008
you have a basic misunderstanding of as3. you're not loading into a movieclip. you're adding a child to a movieclip and that has nothing to do with you're problem.

you're loading using a loader (contentLoader). and that loader contains the loaded content. to remove the loaded content from your application you must remove the loader from your application.

to do that your loader that must by removed from the display list (in your case by removing it from another display object (loader_mc), all streams in the loader's content property must be stopped and all referernces to the loader (including listeners) must be removed and finally you must assign your loader to be null.

then pray, because flash gc doesn't currently work correctly, but that's another issue.
KLACBobAuthor
Participant
August 9, 2008
Thank you for replying kglad. I appreciate you trying to help me through the logic part of it as well. Hopefully as I gain a better understanding I'll be able to troubleshoot better on my own without imposing on people like yourself kind enough to come to the forums to help.

I guess my question based on your reply would then be, is there a better way to approach trying to load external swfs to function with buttons then what I've done or would I be able to actually modify my code to work?

I tried adding a removeChild element like this to the buttons but it didn't work:

function contactClick(event:MouseEvent):void
{
zeusMenu.contact_words.gotoAndPlay("click");
laoder_mc.removeChild(contentLoader);
contentLoader.load(contactRequest);
loader_mc.addChild(contentLoader);
}

My assumption is that coding it in a way that simply removes the contentLoader child will not work. If my objective is to take the five external swfs and get them to "load" and "unload" upon the click of my five buttons, how can I do that? I know that's a hefty question, but any furthur help would be greatly appreciated.