DrewFulton
January 21st, 2009, 05:35 AM
I am in the final stages of my site design and am hung up on a specific loading problem. I have a main swf file that then loads other swf for each page.
I want to load the swf's into a specific MovieClip that is placed on the stage as part of a scroll bar setup. I don't know how to do this. I can simply create a loader and place it in a movieclip I create with AS and then use addchild. This works except for it means I have to place the scroll bar setup on each separate page creating a lot more tedious work and longer loads. Plus, I seem to only be able to load one page and then can't unload the loader to load another page. Major issue obviously.
So here we are... How can I take an external swf, load it into a MovieClip with instance name "content_mc" when a button is clicked. Second, when a different button is clicked, how do I unload the previous swf and load a new one? Below is the code I have so far. I look forward to any help.
Thanks so much.
Drew
stop();
var contentLoader:Loader = new Loader();
menu_mc.project_mc.projectsub.pdescription.addEven tListener(MouseEvent.CLICK, loadContent);
menu_mc.project_mc.projectsub.updates.addEventList ener(MouseEvent.CLICK, loadContent);
menu_mc.team_mc.teamsub.drew.addEventListener(Mous eEvent.CLICK, loadContent);
menu_mc.team_mc.teamsub.greg.addEventListener(Mous eEvent.CLICK, loadContent);
menu_mc.team_mc.teamsub.colin.addEventListener(Mou seEvent.CLICK, loadContent);
menu_mc.team_mc.teamsub.others.addEventListener(Mo useEvent.CLICK, loadContent);
menu_mc.media_mc.mediasub.photo.addEventListener(M ouseEvent.CLICK, loadContent);
menu_mc.media_mc.mediasub.pvideo.addEventListener( MouseEvent.CLICK, loadContent);
menu_mc.media_mc.mediasub.science.addEventListener (MouseEvent.CLICK, loadContent);
menu_mc.outreach_mc.outreachsub.offerings.addEvent Listener(MouseEvent.CLICK, loadContent);
menu_mc.outreach_mc.outreachsub.uevents.addEventLi stener(MouseEvent.CLICK, loadContent);
menu_mc.support_mc.supportsub.sponsors.addEventLis tener(MouseEvent.CLICK, loadContent);
menu_mc.support_mc.supportsub.donate.addEventListe ner(MouseEvent.CLICK, loadContent);
var subButtonSelect; // Holds Name of Button Currently Selected
var subbuttonArray:Array = [menu_mc.project_mc.projectsub.pdescription, menu_mc.project_mc.projectsub.updates, menu_mc.team_mc.teamsub.drew, menu_mc.team_mc.teamsub.greg, menu_mc.team_mc.teamsub.colin, menu_mc.team_mc.teamsub.others, menu_mc.media_mc.mediasub.photo, menu_mc.media_mc.mediasub.pvideo, menu_mc.media_mc.mediasub.science, menu_mc.outreach_mc.outreachsub.offerings, menu_mc.outreach_mc.outreachsub.uevents, menu_mc.support_mc.supportsub.sponsors, menu_mc.support_mc.supportsub.donate]
var contentArray:Array = ["pdescription.swf", "updates.swf", "drew.swf", "greg.swf", "colin.swf", "others.swf", "photo.swf", "pvideo.swf", "science.swf", "offerings.swf", "uevents.swf", "sponsors.swf", "donate.swf"];
function loadContent(event:MouseEvent):void {
for(var i:int = 0; i < subbuttonArray.length; i++) {
if(event.currentTarget == subbuttonArray[i]) {
if(subButtonSelect != null)
{
removeChild(content_swf);
}
contentLoader.load(new URLRequest(contentArray[i]));
contentLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, onContentLoaded);
subButtonSelect = event.currentTarget;
}
}
}
function onContentLoaded( event:Event ):void{
content_swf = MovieClip(contentLoader.content);
addChild(content_swf);
}
I want to load the swf's into a specific MovieClip that is placed on the stage as part of a scroll bar setup. I don't know how to do this. I can simply create a loader and place it in a movieclip I create with AS and then use addchild. This works except for it means I have to place the scroll bar setup on each separate page creating a lot more tedious work and longer loads. Plus, I seem to only be able to load one page and then can't unload the loader to load another page. Major issue obviously.
So here we are... How can I take an external swf, load it into a MovieClip with instance name "content_mc" when a button is clicked. Second, when a different button is clicked, how do I unload the previous swf and load a new one? Below is the code I have so far. I look forward to any help.
Thanks so much.
Drew
stop();
var contentLoader:Loader = new Loader();
menu_mc.project_mc.projectsub.pdescription.addEven tListener(MouseEvent.CLICK, loadContent);
menu_mc.project_mc.projectsub.updates.addEventList ener(MouseEvent.CLICK, loadContent);
menu_mc.team_mc.teamsub.drew.addEventListener(Mous eEvent.CLICK, loadContent);
menu_mc.team_mc.teamsub.greg.addEventListener(Mous eEvent.CLICK, loadContent);
menu_mc.team_mc.teamsub.colin.addEventListener(Mou seEvent.CLICK, loadContent);
menu_mc.team_mc.teamsub.others.addEventListener(Mo useEvent.CLICK, loadContent);
menu_mc.media_mc.mediasub.photo.addEventListener(M ouseEvent.CLICK, loadContent);
menu_mc.media_mc.mediasub.pvideo.addEventListener( MouseEvent.CLICK, loadContent);
menu_mc.media_mc.mediasub.science.addEventListener (MouseEvent.CLICK, loadContent);
menu_mc.outreach_mc.outreachsub.offerings.addEvent Listener(MouseEvent.CLICK, loadContent);
menu_mc.outreach_mc.outreachsub.uevents.addEventLi stener(MouseEvent.CLICK, loadContent);
menu_mc.support_mc.supportsub.sponsors.addEventLis tener(MouseEvent.CLICK, loadContent);
menu_mc.support_mc.supportsub.donate.addEventListe ner(MouseEvent.CLICK, loadContent);
var subButtonSelect; // Holds Name of Button Currently Selected
var subbuttonArray:Array = [menu_mc.project_mc.projectsub.pdescription, menu_mc.project_mc.projectsub.updates, menu_mc.team_mc.teamsub.drew, menu_mc.team_mc.teamsub.greg, menu_mc.team_mc.teamsub.colin, menu_mc.team_mc.teamsub.others, menu_mc.media_mc.mediasub.photo, menu_mc.media_mc.mediasub.pvideo, menu_mc.media_mc.mediasub.science, menu_mc.outreach_mc.outreachsub.offerings, menu_mc.outreach_mc.outreachsub.uevents, menu_mc.support_mc.supportsub.sponsors, menu_mc.support_mc.supportsub.donate]
var contentArray:Array = ["pdescription.swf", "updates.swf", "drew.swf", "greg.swf", "colin.swf", "others.swf", "photo.swf", "pvideo.swf", "science.swf", "offerings.swf", "uevents.swf", "sponsors.swf", "donate.swf"];
function loadContent(event:MouseEvent):void {
for(var i:int = 0; i < subbuttonArray.length; i++) {
if(event.currentTarget == subbuttonArray[i]) {
if(subButtonSelect != null)
{
removeChild(content_swf);
}
contentLoader.load(new URLRequest(contentArray[i]));
contentLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, onContentLoaded);
subButtonSelect = event.currentTarget;
}
}
}
function onContentLoaded( event:Event ):void{
content_swf = MovieClip(contentLoader.content);
addChild(content_swf);
}