| XML child bindings and change watchers in actionscript |
|
I have spent the better part of two days trying to figure out this issue about XML and setting changewatchers on child elements. I ended up talking to Mike at DigitalPrimates to find the answer. Here is the short of the conversation. Preface When you have itemrenderers bound to an xmllist, and each item is
bound to the xml object their properties update when the xml data is updated. Even if I had a list with a single element like <observations> <observation> <name>Josh</name> <report_text>needs help</report_text> <observation> <observations> And maybe I change the data outside the itemrenderer, like name to "Joshua" The label would reflect the change as long as I put the code to assigne label.text in the overridde set data method Short Question: How do I add a change watcher to a child node of XML or some way for a child of a stack to know that the XML it holds a reference to has been updated elsewhere in the program with as3? Short Answer "When you have itemrenderers bound to an xmllist" No such concept. If you look in the datagrid or list controls, as soonas you pass it an XMLList, it wraps it in an XMLListCollection. XMLListCollections broadcast an event named collectionChange when their contents change. That is how list controls know to reset the data on your item renderer. My Solution (Dirty, but it worked) Pass reference to the xml into a new xmllistcollection with an event listener xmlC = new XMLListCollection() xmlC.addItem(myXML) xmlC.addEventListener( If anyone comes up with a better way I'd love to hear it
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
|