Hi,
I am having a fair amount of trouble with arrays. I have some script which grabs stuff from an xml file. The stuff grabbed from the xml is in a loop to create an automatic menu. This is all fine and dandy. Say there are 9 items in the xml file, I get 9 menu items with their unique id’s.
What I want to do is define an array for comparison against the info taken from the xml file. Say in the xml file I have nodes set up for Apple, Pear, Banana and Orange. With my current script I would get a menu with these items on it. What I need to do is be able to specify the items I want to appear on the menu. For this example I would want Apple and Banana only.
I have experimented with if statements, and it takes too much code to accomplish what I want I am sure there is a more compact way. My idea is to set an array with the items I want in it, then when the information is taken from the xml file, I need the script to do the function of creating menu items only with the items I have specified in the array. Below I have added the code, which has been modified from Kirupa’s own squirrel finder tutorial. I need the code to be as reusable as possible, ie only the array would need to change. In my code the variable featureType would contain the information I need to compare against.
Any help is much appreciated. I have googles arrays and have read information on arrays from a book I own, but cannot quite get it.
//set limits on the features that need to display
// define array
var featureLimits:Array = ["Apple", "Banana"];
//filter function to get correct info from xml file
//and send variables to relevant areas
function createFeaturesMenu(){
var features = features_xml.firstChild.childNodes;
for(var i:Number = 0; i < features.length; i++){
var featureType = features*.attributes.type;
trace(featureType);
var featureLabel = features*.firstChild;
var featureDescription = features*.childNodes[1];
var feature_mc = menu_mc.attachMovie("menu_item","item" + item_count, item_count);
//count menu_items and increase distance between menu_items
feature_mc._y = item_count * item_spacing;
item_count++;
//set text format on menu_item text fields
feature_mc.feature_txt.embedFonts = true;
feature_mc.feature_txt.antiAliasType = "advanced";
feature_mc.feature_txt.setNewTextFormat(menuFormat);
//pass variables out to text areas
feature_mc.feature_txt.text = "> " + featureLabel.firstChild.nodeValue;
feature_mc.feature_btn.featureText = featureDescription.firstChild.nodeValue;
feature_mc.feature_btn.featureLogo = featureType;
feature_mc.feature_btn.onRelease = DisplayInfo;
}
};