Can any one help? I’m new to AS3, shakey at AS2 and in over my head. I have an external XML file I want to load elements of into a dynamic text field and in turn use the text listing as buttons to launch image and other XML files. I get the XML to load but either I get the first element, or all the elements in one line. How do I iterate through the list appending each element to the list? The sample below puts “Air Cleaner” in the text field. The child of “catpage” is the element I want to list.
//AS3 Sample
var xmlPath:String = “data/xml/”;
var priceListXML:XML;
var menuWords:String = “data/xml/menutest.xml”;
var xmlFile:String = “014.XML”;
var fileType:String = “.jpg”;
var ltCatPage:Number;
var rtCatPage:Number;
var zoomImg:Number;
//Menu loader – must include menu text and images
var xmlMenuLoader:URLLoader = new URLLoader();
var xmlMenuData:XMLList = new XMLList();
xmlMenuLoader.addEventListener(Event.COMPLETE, loadMenuXML);
xmlMenuLoader.load(new URLRequest(menuWords));
function loadMenuXML(e:Event):void {
xmlMenuData = new XMLList(e.target.data);
buildMenu(xmlMenuData);
}
function buildMenu(catagory:XMLList):void {
var menuText:XMLList = xmlMenuData;
menuList_txt.appendText(catagory.catsect.catpage.children()[0]);
trace (menuText);
}
The XML is loading and I’m able to access it. When I trace it with my “trace (menuText);” statement, it appears in the output panel. I also get various versions appear in my text field. What I’m having trouble with is stepping through all the children of the catpage element and adding them one by one to my text field each on a new line.
you are faster at the reply then I. The + “\N” did the trick. I tried different versions of that with no avail. So I learn something, you created the var item from the information stored in xmlMenuData, specifically catpage. Then used the … operator to step out of catpage? Each time you went through the loop you appended catpage on a new line.
Thanks again for you assistance. I should have gone here soon, I could have saved some follicles.
[quote=mattrock23;2353229]For each…in statements work like this: set a variable to represent each piece in a data set (array or xmlList). Then the code inside the brackets is executed for each piece in the set. If you want something done to each piece, refer to it in the code by the variable.