I’m fairly new to AS3.
What I’m trying to is create a multiframe SWF (main.swf) that loads several external SWFs (ext.swf) on each frame. I’ve got that to work. My problem is that I’m trying to assign actions to buttons/MovieClips in the external swfs that navigate to different frames in my main.swf.
I want to avoid hard coding the buttons because there are about 30 external SWFs and they don’t all have the same number of buttons within them.
The approach I took was creating two arrays in each ext.swf, one to hold the button instances and the other to hold the frame destination labels.
ex.
var buttons:Array = [link1, link2, link3, link4, link9, link10, link20, link21];
var links:Array = ["c1", "c2", "c3", "c4", "c1", "d1", "d2", "e1"];
Then in the main.swf, I created a function that loads the ext.swf and runs a “for” loop that assigns EventListeners to the contents of the “buttons” array to go to the frame labels defined in the “links” array.
var loadee:MovieClip;
loadFile("ext1.swf");
function loadFile(externalSWF:String):void {
var loader:Loader = new Loader();
addChild(loader);
loader.load(new URLRequest(externalSWF));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, callLoadee, false, 0, true);
function callLoadee(evt:Event):void {
loadee=MovieClip(loader.content);
assignLinks();
evt.target.removeEventListener(Event.INIT, callLoadee);
}
}
var holdLink:String;
function assignLinks():void {
var arrayLength:Number = loadee.buttons.length;
var importArray:Array = loadee.links;
for (var i:int = 0; i < arrayLength; i++) {
holdLink = importArray*;
trace (holdLink);
loadee.buttons*.addEventListener(MouseEvent.CLICK, navToPage);
}
}
function navToPage(evt:MouseEvent):void {
gotoAndStop(holdLink);
trace (holdLink);
}
The “for” loop in the “assignLink” processes and traces the “links” array just fine, but it always assigns the last array item to every button. Any help would be much appreciated.
Thanks
malamin