1 Reply Latest reply on Dec 18, 2007 6:31 AM by soup_pot

    Modifying 'current node' of XML object


      I'm trying to edit the 'current node' of an XML object but I don't always know what the current node will be.

      My XML object loads an external XML file:

      <mx:XML id="featureData" source="assets/article_text.xml"/>

      and I read that data via an <mx:Repeater> which creates a <mx:TextArea> for each 'currentItem'

      <mx:Repeater id="repeatParas" dataProvider="{featureData.body_text.children()}">
      <mx:TextArea htmlText="{repeatParas.currentItem}" width="80%" borderStyle="none" click="showBodyEditor(event, event.currentTarget.getRepeaterItem())" verticalScrollPolicy="off" creationComplete="resizeTextArea(event);" updateComplete="resizeTextArea(event);"/> </mx:Repeater>

      A click event on <mx:TextArea> loads a popup window containing a RichTextEditor containing the content of currentItem:

      private function showBodyEditor(event:Event, item:String):void {
      var pop1:BodyEditor = BodyEditor(PopUpManager.createPopUp(this, BodyEditor, true));
      //Set properties of the BodyEditor custom component.
      pop1.targetBodyText = event.currentTarget;
      pop1.currentNode = item;

      I then pass the value of whatever was entered in the RichTextEdior back to the initial <mx:TextArea> via a click event function on a button labeled 'done' (processBodyText()):

      public var targetBodyText:Object;
      public var currentNode:String;

      // Pass data back to text areas
      private function processBodyText():void {
      targetBodyText.htmlText = String(bodyTextForm.htmlText);
      currentNode = String(bodyTextForm.htmlText);
      // remove pop up.

      But what I can't seem to do is actually update that node in the featureData XML object without explicitly saying which node to update (e.g. this works: parentApplication.featureData.body_text.p[1] = String(bodyTextForm.htmlText);) I don't necessarily know which node to update, I just want to be able to update whatever node I happen to be editing at the time.

      Is this possible?

      Thanks to anyone who can shed some light!
        • 1. Re: Modifying 'current node' of XML object
          soup_pot Level 1
          I'm going to answer my own post (in case anyone was watching).

          I simply changed the currentNode parameters/variables to type Object (instead of String) and within the processBodyText function I replaced

          currentNode = String(bodyTextForm.htmlText);



          which actually updates the node in the XML data provider.

          I still need to get rid of some of the html gobblygook that gets passed back (e.g &lt;TEXTFORMAT LEADING="2"&gt;) but as long as I'm able to update the current node I'm happy (for now).