OK, so here's what I'm trying to do:
I have a landing page with 3 buttons on it, and I have 3 corresponding external swf files, one for each button... so the user clicks a button and the corresponding swf file is loaded into an empty MC on the stage. Now each of these external swf files also contains several buttons and each of these buttons when clicked will fire off a click event, each buttons event in each swf is uniquely named based on the button name and the swf file name (ex: swf1_button1_click) So in the main swf file after a button is clicked I loop through the 3 main buttons and add listeners to the contents of the empty holder clip for each of the buttons so its listening for "swf1_button1_click", "swf1_button2_click", "swf2_button1_click"... so on and so forth.
Now this all works, clips load in correctly, events fire and are heard approperatly meaning the empty clip does recieve the "swf1_btn1_click" event and it fires the code associated with that event correctly, but the problem is with the function being called, Here is the code in question...
The function for loading the external swf files:
function loadCommunity(e:MouseEvent) {
var mLoader:Loader = new Loader();
var community:String = MovieClip(e.currentTarget).name;
trace("Loading " + community);
var mRequest:URLRequest = new URLRequest(DevSite+"/flash/" + community + ".swf?community=" + community);
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, displayCommunity);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, function(e:ProgressEvent) {
var percent:Number = e.bytesLoaded / e.bytesTotal;
percent = Math.round(percent * 100);
trace(percent + "% loaded");
});
mLoader.load(mRequest);
}
The code for assigning the event listeners:
function displayCommunity(e:Event) {
for (var i = 0; i < mcCommunityHolder.numChildren; i++) {
mcCommunityHolder.removeChild(mcCommunityHolder.getChildAt(i));
}
mcCommunityHolder.alpha = 0;
mcCommunityHolder.visible = true;
mcCommunityHolder.addChild(e.currentTarget.content);
TweenLite.to(mcCommunityHolder, 1, {alpha:1, easing:Elastic.easeOut});
var newClip:MovieClip = MovieClip(mcCommunityHolder.getChildAt(mcCommunityHolder.numChildren - 1));
for each (var mc:MovieClip in mcCommunities) {
var commName:String = mc.name.toLowerCase();
trace(" ... " + commName + " ... ");
newClip.addEventListener(commName + "_btnMap", function(e:Event) { trace("clicked: " + commName); viewLotmap(commName); });
newClip.addEventListener(commName + "_btnLocation", function(e:Event) { trace("clicked: " + commName); viewLocationmap(commName); });
newClip.addEventListener(commName + "_btnAriel", function(e:Event) { trace("clicked: " + commName); arielPhotos(commName); });
newClip.addEventListener(commName + "_btnRegister", function(e:Event) { trace("clicked: " + commName); communityRegister(commName); });
}
}
So what I'm getting is: no matter what external swf's button I have clicked the events of the buttons within it act as though I where clicking a button from within external swf 3... make sense?
heres an example: I click Button1, external swf 1 loads and displays, within external swf 1 I click button 1 which fires off its event "swf1_btn1_click" and the main swf sees it as such, but when this function ("communityRegister(commName);") is called within the listener event, "commName" is always the same value (the value that btn3 of the main swf should have).
So my main flash piece is treating every external swfs events as though they where coming from external swf 3. The best way I can explain it is: Its treating "commName:String" as if it where a reference variable and when I resign it on every iteration of the loop, the previous uses of it also change to the new value so every time I've used it is always set to the value of the last time it where assigned...
Gahh!!, what a brain wreck, haha... I've had this issue many times before and never actually figured it out. I've always just managed to re work the code until it fixed its self, but I'm tire of doing that and I want to know why this happens. I'm not interested in other ways of coding what I want to do, I need to know what is going on to cause this sort of behaviour so don't be shy about getting technical ;)
Thanks in advance.