Build a property name and, consequently, an element name, dynamically : Bracket syntax « XML « Flash / Flex / ActionScript






Build a property name and, consequently, an element name, dynamically

 


package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var example:XML = <example />;
        
        var id:int = 10;
        
        // Create a string to incorporate the value of id in the node name
        example[ "user" + id ] = "";    
        
        trace( example );
    }
  }
}

        








Related examples in the same category

1.Bracket syntax is required for illegal property name
2.Adding Text Nodes to an XML Object
3.Use bracket notation, coupled with an integer, to access a particular element node
4.Use a variable's value as the element name to find:
5.XML text in a String into an actual XML object, whereas a cast would fail.
6.Accessing Values with E4X: Using the Dot Operator to Access Elements