Yordan Yanakiev
Yordan Yanakiev

Reputation: 2604

Flex : Add elements to XMLListCollection?

I have a MenuBar, which is using a XMLListCollection object as a dataProvider. I wish to add and remove elements from this collection at runtime.

// all suggestions which will improve the main idea is more than appreciated. :)

Upvotes: 0

Views: 2574

Answers (2)

The_asMan
The_asMan

Reputation: 6402

To add

collectionName.addChild(o:object)

To remove

collectionName.removeChild(index:int);

Upvotes: 1

Jonathan Rowny
Jonathan Rowny

Reputation: 7588

For me personally, it's easier to use an ArrayCollection as a dataprovider. You can use ArrayCollections as long as your objects have the "children" property, the children array will become your submenus. If working with ArrayCollections is easier for you, this may be a good route. Here's a good example of that: http://flexoop.com/2008/11/databinding-with-menubar-dataprovider/

You can modify XML/XMLLists easily using e4x. Here's a link on how to work with XML/XMLList: http://livedocs.adobe.com/flex/3/html/help.html?content=13_Working_with_XML_03.html

There's a function called appendChild and you can delete nodes by simply using the delete keyword on a selected node.

delete someXML.someChild[0];

Here's a good article on working with XML: http://blogs.4point.com/armaghan.chaudhary/2009/08/xml-manipulation-in-flex-and-actionscript.html

XML functions/techniques should work fine with XMLList (and XMLListCollection).

Upvotes: 3

Related Questions