AS 3.0 problem : please help with this loading external swf problem :)

Please download my file here : http://www.djboudicca.com/lin_flash.zip

Hi there everyone…

Thanks for taking the time to check this out. I’m a multimedia student (struggling) to get this assignment done in AS 3.0…

My assignment has to be done only in AS 3.0…

Basically, you need to open up the main.fla to see what I mean…

* main.swf - holds the main website menu
* articles.swf - is one of the swfs which get loaded into main.swf (via the main.swf main menu)

THE PROBLEM : Articles.swf has another ‘sub-menu’ containing links to article1.swf, article2.swf and arcticle3.swf. I’ve tried to use the ‘same logic’ as main.swf to do the loading of article1.swf etc into articles.swf… It just doesn’t work when I try to access articles.swf from main.swf. Maybe it’s clashing with the code used in main.swf?

However when I open up articles.fla and ‘Test movie’ all the article1.swf etc load into it perfectly, just doesn’t want to function when entered from main.swf…

THE CODE I USED IN MAIN.SWF TO LOAD all other swfs :

// setup labels on the dynamic buttons
home_btn.setLabel("home");
articles_btn.setLabel("articles");
gallery_btn.setLabel("gallery");
contact_btn.setLabel("contact");
promoSignUp_btn.setLabel("sign up here");

//setup array to load in different page content
var clips:Array = ["home.swf", "articles.swf", "gallery.swf","contact.swf","promoSignUp.swf"];

var thisLoader:Loader = new Loader();
thisLoader.contentLoaderInfo.addEventListener(Even t.INIT, doneLoading);
var loaded_mc:MovieClip = new MovieClip();
stage.addChild(loaded_mc);

function doneLoading(event:Event) {
stage.removeChild(loaded_mc);
loaded_mc = MovieClip(thisLoader.content);
thisLoader.unload();
stage.addChild(loaded_mc);
loaded_mc.x=150;
loaded_mc.y=150;
loaded_mc.gotoAndPlay(1);
}

thisLoader.load(new URLRequest(clips[0]));

home_btn.addEventListener(MouseEvent.CLICK, loadHome);

function loadHome(event:MouseEvent){
//FIRST RESET ALL OTHER BUTTONS
//ie. release any other buttons if they have been selected/clicked
//and left in a "down" state
//ie. put all other buttons in the "up" state
//+ set the buttons' variable 'clicked' to 'false'
//[this is done within each button in the 1st frame]
articles_btn.gotoAndStop("up")
gallery_btn.gotoAndStop("up")
contact_btn.gotoAndStop("up")
promoSignUp_btn.gotoAndStop("up")

//load the "home.swf" file, 1st element [0] in the array
thisLoader.load(new URLRequest(clips[0]));
}

articles_btn.addEventListener(MouseEvent.CLICK, loadArticles);

function loadArticles(event:MouseEvent){
//FIRST RESET ALL OTHER BUTTONS
home_btn.gotoAndStop("up")
gallery_btn.gotoAndStop("up")
contact_btn.gotoAndStop("up")
promoSignUp_btn.gotoAndStop("up")
//load the "articles.swf" file, 2nd element [1] in the array
thisLoader.load(new URLRequest(clips[1]));
}

gallery_btn.addEventListener(MouseEvent.CLICK, loadGallery);

function loadGallery(event:MouseEvent){
//FIRST RESET ALL OTHER BUTTONS
home_btn.gotoAndStop("up")
articles_btn.gotoAndStop("up")
contact_btn.gotoAndStop("up")
promoSignUp_btn.gotoAndStop("up")
//load the "gallery.swf" file, 3rd element [2] in the array
thisLoader.load(new URLRequest(clips[2]));
}

contact_btn.addEventListener(MouseEvent.CLICK, loadContact);

function loadContact(event:MouseEvent){
//FIRST RESET ALL OTHER BUTTONS
home_btn.gotoAndStop("up")
articles_btn.gotoAndStop("up")
gallery_btn.gotoAndStop("up")
promoSignUp_btn.gotoAndStop("up")

//load the "contact.swf" file, 4th element [3] in the array
thisLoader.load(new URLRequest(clips[3]));
}
promoSignUp_btn.addEventListener(MouseEvent.CLICK, loadPromoSignUp);

function loadPromoSignUp(event:MouseEvent){
//FIRST RESET ALL OTHER BUTTONS
home_btn.gotoAndStop("up")
articles_btn.gotoAndStop("up")
gallery_btn.gotoAndStop("up")
contact_btn.gotoAndStop("up")

//load the "promoSignUp.swf" file, 5th element [4] in the array
thisLoader.load(new URLRequest(clips[4]));
}

**
THE CODE I USED IN ARTICLES.SWF TO LOAD article1.swf, article2.swf and article3.swf :**

// setup labels on the dynamic buttons
article1_btn.setLabel("DJ Bare Essentials vol 1");
article2_btn.setLabel("Bit of headspace");
article3_btn.setLabel("article3");


//setup array to load in different page content
var clips:Array = ["article1.swf", "article2.swf", "article3.swf"];

var thisLoader:Loader = new Loader();
thisLoader.contentLoaderInfo.addEventListener(Even t.INIT, doneLoading);
var loaded_mc:MovieClip = new MovieClip();
stage.addChild(loaded_mc);

function doneLoading(event:Event) {
stage.removeChild(loaded_mc);
loaded_mc = MovieClip(thisLoader.content);
thisLoader.unload();
stage.addChild(loaded_mc);
loaded_mc.x=0;
loaded_mc.y=0;
loaded_mc.gotoAndPlay(1);
}

thisLoader.load(new URLRequest(clips[0]));

article1_btn.addEventListener(MouseEvent.CLICK, loadArticle1);

function loadArticle1(event:MouseEvent) {
//FIRST RESET ALL OTHER BUTTONS
//ie. release any other buttons if they have been selected/clicked
//and left in a "down" state
//ie. put all other buttons in the "up" state
//+ set the buttons' variable 'clicked' to 'false'
//[this is done within each button in the 1st frame]
article2_btn.gotoAndStop("up");
article3_btn.gotoAndStop("up");
//load the "article1.swf" file, 1st element [0] in the array
thisLoader.load(new URLRequest(clips[0]));
}

article2_btn.addEventListener(MouseEvent.CLICK, loadArticle2);

function loadArticle2(event:MouseEvent) {
//FIRST RESET ALL OTHER BUTTONS
article1_btn.gotoAndStop("up");
article3_btn.gotoAndStop("up");
//load the "article2.swf" file, 2nd element [1] in the array
thisLoader.load(new URLRequest(clips[1]));
}

article3_btn.addEventListener(MouseEvent.CLICK, loadArticle3);

function loadArticle3(event:MouseEvent) {
//FIRST RESET ALL OTHER BUTTONS
article1_btn.gotoAndStop("up");
article2_btn.gotoAndStop("up");
//load the "article3.swf" file, 3rd element [2] in the array
thisLoader.load(new URLRequest(clips[2]));
}

stop();

I would be very grateful for any help you can offer me…!!

Many thanks

BeeDee

basically your being a bit unclear, and thats alot of code to look through, not many of us would like to redo your whole project for you. So could i ask you to be more specific and in shorter words and less code, on what exactly you need help with

I didn’t read all of your code, so this is just a guess. this is a common problem too…
if your articles.swf and main.swf are in different directories:
in your articles.swf, use the directory as the “reference” point for the paths…

so, if your path looks like this:
-main.swf
–/movies subdirectory/
—+articles.swf
----/articles subdirectory/
-----+article1.swf
-----+article2.swf

the url for article1.swf would be /movies subdirectory/articles subdirectory/article1.swf in relation to main.swf

basically, when you load a swf into another swf, it’s path changes to the path of the parent swf.

Holy heck… looks like one of those problems as a teacher where there’s obviously a lot of effort gone into it, but finding the issue is tricky. Reminds me of a subject I taught that now using AS3.0 - teaching it in AS2.0 was a challenge as it was :wink:

I can already spot that there’d be a few issues with unloading - you’re forcing listeners into child objects, which need to be removed, as otherwise they’ll remain in memory and not be mark / swept. It’s not a path issue as john has suggested - all SWFs are in the same level.

Hmm… as articles.swf is loaded, it may be that you’re getting a 1009 error, which means - don’t start running your code until the stage has initialised. You need to listen for Event.ADDED_TO_STAGE, and then add your event listeners for the buttons… that might be it… hmm…

There are certainly ways that could help organisation of code in the future - there’s a lot of redundancy, but as I remember learning AS myself, that redundancy is helpful whilst you figure out how everything fits together :slight_smile:

Anyway, have a look at that event, as that may be the issue… but yeah. It’s the context that’s hard, not necessarily the problem.