3 Replies Latest reply on Jul 30, 2007 11:10 AM by ntsiii

    Parsing XML

    tbojb
      Hi,

      I'm trying to parse XML like this:
      var myXML:XML = new XML('<mx:TextArea id="taMessage2" text="Test Message Insert" width="250" height="150" x="33" y="127" borderThickness="4" borderColor="#0000a0" cornerRadius="19" alpha="1.0" borderStyle="solid"/>');

      I get the following runtime error:
      TypeError: Error #1083: The prefix "mx" for element "mx:TextArea" is not bound.

      Can anyone explane how to dynamically add components to the UI using XML?

      Thanks in advance.

      Johan Blaauw
        • 1. Re: Parsing XML
          AndyWW Level 1
          If you actually have single quotes around the parameter to the XML constructor and double quotes around the attribute values (e.g., "taMessage2") then I think you just need to change the two single quotes to double quotes, and the double quotes to single quotes. Strings in AS (unlike Pascal) are enclosed in double quotes. This may work for you:

          var myXML:XML = new XML("<mx:TextArea id='taMessage2' text='Test Message Insert' width='250' height='150' x='33' y='127' borderThickness='4' borderColor='#0000a0' cornerRadius='19' alpha='1.0' borderStyle='solid'/>");

          If you also have linefeeds in your string then you will also need to use concatenation for the parameter, e.g.:

          var myXML:XML = new XML("<mx:TextArea id='taMessage2'" +
          " text='Test Message Insert' width='250' height='150'" +
          " x='33' y='127' borderThickness='4' borderColor='#0000a0'" +
          " cornerRadius='19' alpha='1.0' borderStyle='solid'/>");
          • 2. Re: Parsing XML
            tbojb Level 1
            Andy, thanks for your reply.

            The error I got was because the XML was not well formed.
            After I included the location where mx can be found the error was gone.

            How ever the question I have is not answered unfortunatly.

            How can I insert dynamically UI components like the mx:TextArea at runtime parsing XML?
            • 3. Re: Parsing XML
              ntsiii Level 3
              Also, be aware of "literal" xml:
              var sAttr2val:String = "myValue2";
              var xmlData:XML = <root attr1="attr1value"><node attr2={sAttr2} /> </root>;

              Tracy