Flex - data binding from tree to repeater

I am trying to create an XML question editor in flash. Basically I am loading XML into a Tree component - XML ​​like:

<questions>
<question id="1" type="radio" text="This is question 1" isBranch="true">
  <option id="1.1" correct="false" text="This is option 1" />
  <option id="1.2" correct="false" text="This is option 2" />
  <option id="1.1" correct="false" text="This is option 1" />
  <option id="1.2" correct="false" text="This is option 2" />
  <option id="1.3" correct="true" text="This is option 3" />
  <option id="1.4" correct="false" text="This is option 4" />
</question>
<question id="2" type="check" text="This is question 2" isBranch="true">
  <option id="2.1" correct="true" text="This is option 1" />
  <option id="2.2" correct="false" text="This is option 2" />
  <option id="2.3" correct="true" text="This is option 3" />
</question>
</questions>

      

So that goes to the tree. On change, I get a list of options for the selected question (item..option) - and that XMLList is passed to the (custom) component. This component (not sure if this is the best way to do it, but still ...) - has a couple of Repeater elements - one that is bound to the XMLList for radio, the other is bound to the XMLList check box question. Each repeater sets the number of options, puts a TextInput in (for editing the option text) and either a radio or a checkbox (depending on the type of question)

So - what I need is when the text is edited for the option, the XML is that the TextInput is bound to XML, which is the dataProvider for the tree. For example, if "This is option 1" is changed to "This is option Foo" - the tree is updated with this.

So far my repeater (for radios for example) is like this

<mx:Repeater id="repeaterRadio" dataProvider="{optionsListRadio}">      
  <mx:TextInput width="359" id="radioText"
     editable="true" enabled="true" text="{repeaterRadio.currentItem.@text}"/>
  <mx:RadioButton id="radioArray"
    data="{repeaterRadio.currentItem.@id}"
    selected="{repeaterRadio.currentItem.@correct=='true'}"/>
</mx:Repeater>

      

Binding doesn't work - all I get are warnings like:

warning: unable to bind to property 'text' on class 'XML' (class is not an IEventDispatcher)

      

I understand why this is the case, but I do not understand how to bind data that the user can edit back to the original xml. I know that I can make the tree editable, but this is not really an option.

So any pointers or ideas would be much appreciated!

+1


source to share


2 answers


I think there are two classes that can help convert XML to bindable and then convert back to XML when user is ready, mx.rpc.xml.SimpleXMLDecoder and mx.rpc.xml.SimpleXMLEncoder



0


source


Just replace repeaterRadio.currentItem.@text

with XML(repeaterRadio.currentItem).@text

.



0


source







All Articles