This last part of the code Brings all the preparation togeather by calling a PHP Script which reads the files in the directory that can be linked to for our Flash movie then sends their names.
Start with a LoadVars Object which allows us to load Data into a Flash Movie from a number of sources.

myLabels=new LoadVars();
myLabels.load("script/menus.php");



Now we use the onLoad event to make sure we don't try to set up our menus before we know how many we we need.

myLabels.onLoad=function(){



The PHP Script outputs variables in name value pairs separated by ampersands which is how Flash likes it's variables

&one=PART1&two=PART2&


Each of the numbers one and two is going to be a variable name in ActionScript associated with the value 'PART1' and 'PART2' respectively.

The PHP finishes this output with the variable 'num' which tells us how many items it found. So we can loop through and extract each of the file names into an array.

for(i=0;i<Number(myLabels.num);i++){



The trick in this next line of code is that the array menuItems is being populated with the variables one,two, three etc from the myLabels object sent by the PHP Script.

The itemNum array, defined at the begining of the script, holds the names of the variables we expect to receive.

NB: The itemNum array is evaluated each time the line of code is executed, it will be myLabels.one on the first iteration of the loop.

menuItems[i]=myLabels[itemNum[i]];
}// end for



Once all that is sorted out now it's time to actually put all the menus on the stage, populate their values and set their position. Do this with a loop based on how many values have been put into the menuItems Array.

//Place menu items on stage
for (i=0; i<menuItems.length; i++) {



Attach each of the movies to the root timeline, making sure thy will be above our highlight_mc movieClip when it is created.

_root.attachMovie("but", menuItems[i], 100+i);



The set each items position and text using the posMe method and txtSet method

// position menus and set text
_root[menuItems[i]].posMe(defX, i*defY);
_root[menuItems[i]].txtSet(menuItems[i]);
}// end for


Don't forget to finish off the code

}// end on load
stop();