5 Replies Latest reply on Jun 20, 2007 6:26 AM by ZClaes

    XML updating problem

    KeenoChris
      hi, i have what i think a very simple task, updating xml strings from form text inputs.
      so basically on clicking a button i had a function trigger the following code to update the XML

      quoteFormXML.customerDetails.name = nameTi.text;
      quoteFormXML.customerDetails.street = streetTi.text;
      quoteFormXML.customerDetails.area = areaTi.text;
      quoteFormXML.customerDetails.city = cityTi.text;
      ....

      basically, it would only update the first call, then stop.
      In the end, i had to put the update command to the change event on the text inputs.

      Am i missing somthing totally obvious here?

      Chris

      thanks in advance

        • 1. Re: XML updating problem
          ntsiii Level 3
          No, that should work. Are you sure "quoteFormXML.customerDetails" is accessible in the scope and at the time of the function call?

          Tracy
          • 2. Re: XML updating problem
            KeenoChris Level 1
            Hi
            thanks for your reply,
            i re-entered the text just to make sure, here is more of it

            [Bindable]
            public var quoteFormXML:XML; //passed in from componenent

            private function saveClick():void{
            updateForm();
            var saveQuoteEvent:SaveQuoteEvent = new SaveQuoteEvent(quoteFormXML,"saveEvent");
            dispatchEvent(saveQuoteEvent);
            }

            private function updateForm():void{
            quoteFormXML.customerDetails.name = nameTi.text;
            quoteFormXML.customerDetails.street = streetTi.text;
            quoteFormXML.customerDetails.area = areaTi.text;
            quoteFormXML.customerDetails.city = cityTi.text;
            //..ommitted some lines here
            }

            there is a button component that triggers saveClick();

            like before, it only updates the name then doesnt update anything else.
            if i ommit the name update it will do the street update, etc etc


            • 3. Re: XML updating problem
              ntsiii Level 3
              The reason I asked is that the only reason I can see that happening is if the code is erroring silently, as it might if customerDetails was undefined in context.

              Suppose you break that code up and debug it?
              var sValue:String = nameTi.text;
              trace("sValue=" + sValue); //make sure you have a good value
              quoteFormXML.customerDetails.name = sValue;
              trace(quoteFormXML.toXMLString()); inspect the current xml
              sValue = streetTi.text;
              trace("sValue=" + sValue)
              quoteFormXML.customerDetails.name = sValue;
              trace(quoteFormXML.toXMLString())
              ...etc.

              Tracy
              • 4. Re: XML updating problem
                KeenoChris Level 1
                great idea i used the debugger and watched some variables

                i think whats happening is this....

                when i update the first value, the XML file detects a change and becuase its a binding goes away and updates the form again to its current values, therefore changing all the rest of the updated values back to the original state.

                how do you set a text boxes text value to a variable without binding it?
                • 5. Re: XML updating problem
                  ZClaes Level 1
                  Just access the text box like any other object (using the ID) and set the .text variable.

                  For example, if you have <mx:TextArea id="my_text" /> in your mxml, the actionscript could just do this:
                  my_text.text = "Helooooooo";

                  Assuming, of course, that the actionscript is within the same component.