views:

1309

answers:

2

Hi, I'm trying to make an XML questions editor in flash. Basically I load in the XML into a Tree component - XML like so:

<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 into the tree. On change I get a list of the options for the selected question (item..option) - and that XMLList is passed into a (custom) component. That component (not sure if this is the best way to go about it but still...) - has a couple of Repeater controls - one which is bound to the XMLList for a radio question, the other bound to the XMLList of a cheque box question. Each repeater loops the number of options, placing a TextInput in (to edit the option text) and either a radio or cheque box (depending on the question type)

So - what I am after is when the text is edited for an option, the XML in that TextInput is bound to the XML which is the dataProvider for the tree. So for example if "This is option 1" is changed to "This is option Foo" - the Tree updates with that.

So far my repeater (eg. for the radios) 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>

No binding works - all I get here is warnings like:

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

I sort of get why this is the case, but am at a loss how to go about binding the data the user can edit back to the source xml. I know I can make the tree itself editable but that's not really an option here.

So any pointers or ideas would be very appreciated!

A: 

I think there are two classes that might be able to help convert the XML into a bindable object, and then reconvert back to XML when the user is finished, mx.rpc.xml.SimpleXMLDecoder and mx.rpc.xml.SimpleXMLEncoder

Lucas Moellers
A: 

just replace repeaterRadio.currentItem.@text with XML(repeaterRadio.currentItem).@text ...

Gert