im having some trouble and i need your help. basically i have my movie which has 18 MCs being used as buttons. each MC has an instance name of “hole0”,“hole1”, “hole2”, “hole3” so on and so fourth all the way up to “hole18”. then for each of those MCs i want to write a loop that will assign a corresponding array index to each MC. in that array are my movie names (“one.swf”, “two.swf”, “three.swf”… “eighteen.swf”). basically i want “hole0” onRelease to load the array’s index of 0. and “hole1” onRelease to load the array’s index of 1… all the way up to 18. does that make sense? i hope so.
the part with my trace command is where (im assuming) i’d put my load movie command, only when i release any MC the entire array is traced rather than the corresponding index…
if you can make any sense of this and can help, you are awesome.
The entire array is being traced because you have the trace function in a for loop which iterates through the entire holeArray array. Try this instead:
it looks like you took out my second loop, so how does flash know which index of the array to reference in my load movie command? it seems to me if i can reference the array index through a loop i should be able to load the corresponding movie…
also i tried your suggestion and i just get undefined…
I see what’s happening. The for-loop is assigning “trace(_root.holeArray[g]);” to all the movieclips. the problem is, after exiting the for-loop ‘g’ is left on 18. So when the user clicks on the movieclips it will trace “_root.holeArray[18]” constantly for all movieclips as ‘g’ was left on 18. This returns “undefined” as holeArray[17] is the last array item. To get around this try the following:
dear lord… ok well first… hmm… you want to look at your methodology, it’ll make it easier in the long run,
if you’re naming them using numbers, why not use the numerals? ie: 1.swf instead of one.swf.
how do you instantiate the 18 mcs? are they attached at run time or static, on the stage? if it’s static you don’t <really> need a dynamic assignment…
using static references, as in _root, could cause you issues later, especially if you load the parent MC in a container, or use a pre-loader from a seperate swf, try to use _parent levels rather than _root.
anyway here’s the band-aid:
holeArray = new Array();
holeArray = ["one.swf", "two.swf", "three.swf", "four.swf", "five.swf", "six.swf", "seven.swf", "eight.swf", "nine.swf", "ten.swf", "eleven.swf", "twelve.swf", "thirteen.swf", "fourteen.swf", "fifteen.swf", "sixteen.swf", "seventeen.swf", "eighteen.swf"];
//
for (g=0; g<holeArray.length; g++) {// holeArray.length will equal 17 as arrays begin at 0
buttonMC = _root["hole" + g];// find out the relative reference, use _root only as a last resort.
buttonMC.arrayLocation = holeArray[g];
buttonMC.onRelease = function() {
mainHolder.loadMovie(this.arrayLocation);
trace ( buttonMC.arrayLocation);
};
}
so it creates the array, then assigns the buttons with their own index, then gives the code to button on what to do when pressed… namely loading it’s array value <number>.swf into a holder MC on the stage, here called mainHolder