1

I am trying to create a xmllist variable in action script like this:

var _menuData:XMLList;              
                <menuitem label="File">
                    <menuitem label="Backup Schedule"/>
                    <menuitem label="Restore Schedule"/>                    
                </menuitem>
                <menuitem label="Edit">
                    <menuitem label="Cut"/>
                    <menuitem label="Copy"/>
                </menuitem>

How do I assign this xml to _menuDAta in actionScript? I dont want to create a string first and then do it all by fixing line break errors. Thanks.

2 Answers 2

3

I can't see your code here but here is a sample code for creating an XMLList:

var xml:XML = <items><item>1</item><item>2</item><item>3</item></items>;
var xmlList:XMLList = xml.item;
trace(xmlList);

Hope it helps, Rob

4
  • I have uncovered the source code in the question, so that you can update your answer.
    – splash
    Mar 17, 2011 at 15:53
  • Thanks Rob,but is there not a direct way of creating XMLList variable? I mean whithout having to add xml variable to list every time? thanks.
    – Tintin
    Mar 17, 2011 at 16:36
  • It seems like you can't populate an XMLList just like that :(
    – robertp
    Mar 17, 2011 at 16:56
  • I can... either make an array of xml elements first and cast it to XMLList or simply make a root node of XMLList and then create xml variable by taking using it's children() property.
    – Tintin
    Mar 17, 2011 at 18:06
-2
var xmlList:XMLList = <><item>1</item><item>2</item><item>3</item></>;
trace(xmlList);
2
  • Adding some explanation along with the code would make this answer better.
    – Thom
    Apr 29, 2014 at 11:42
  • and how does it differ or improve on the old answer
    – mmmmmm
    Apr 29, 2014 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.