Line breaks in dynamically loaded text

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.

//xml sample
<catagory>
<catsect>
<page>001</page>
<sorpage>012</sorpage>
<catpage>Air Cleaner</catpage>
</catsect>
<catsect>
<page>003</page>
<sorpage>014</sorpage>
<catpage>Brake Master Cylinder</catpage>
</catsect>
<catsect>
<page>007</page>
<sorpage>/data/xml/018.xml</sorpage>
<catpage>Clutch</catpage>
</catsect>
</catagory>

//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);
}

I get undefined in the output panel

Make sure to only access the XML inside your loadMenuXML function - otherwise it will not be loaded.

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.

no need to appologize, networks sometime don’t. And thanks for your help.

This code worked as far as displaying the xml in the out put window, but when I direct it to my text field, “menuList_txt” the text is run together.

[quote=mattrock23;2352768]Er, I think I meant :

for each(var item in xmlMenuData..catpage) {
  trace(item.text());
}

should go in the buildMenu function.[/quote]

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

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.

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/statements.html#for_each..in

The … operator is for descendants. Meaning any element anywhere in the xml tree with the name that you specify become part of the list.

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/operators.html#descendant_accessor[/quote]