0

if (child is WinCRLFTextArea) { var node:XML;

                        node = <{child.name}>{WinCRLFTextArea(child).text}</{child.name}>;
                        textXML.appendChild(node);
                    }

I want to add an attribute like "beginIndex" and "endIndex" to node element. dynamically i need to assign values to this attributes. ex: beginIndex = WinCRLFTextArea(child).text.length is it possible ? please anyone help me out for this.

Thanks in advance.

viji
  • 119
  • 2
  • 3
  • 12

1 Answers1

1

You can add/edit/read attributes with the ”@” operator.

var myXML:XML = <xml> <some> <node/> </some> </xml>;

myXML.some.node.@beginIndex = "1";

trace( myXML.some.node.@beginIndex ); // output: 1;
T. Richter
  • 369
  • 1
  • 13
  • I have tried like this "node.{child.name}.@beginIndex = 0;" but it showed error as "Access of undefined property beginIndex node"... How to proceed further ?Thanks... – viji Aug 12 '13 at 10:36
  • I don't completely understand the usage of the {} brackets here. I guess you are trying to use the mxml databinding inside a script clock? This is not going to work. in e4x ( the set of instructions you can use for xml processing in actionscript) you would have to use normal () brackets. You can read more about e4x here: http://livedocs.adobe.com/flex/3/html/help.html?content=13_Working_with_XML_03.html – T. Richter Aug 12 '13 at 14:38
  • Generally, I would a) create an event handler to notice when child.name changes. b) write the value to a `var myNameVar:String` and call your if block c) in that block use your var like this `node.(name()==myNameVar).@beginIndex="1";`But that is strictly spoken not part of your original question, so please don't forget to accept ;) – T. Richter Aug 12 '13 at 14:39