Use bracket notation, coupled with an integer, to access a particular element node : Bracket syntax « XML « Flash / Flex / ActionScript






Use bracket notation, coupled with an integer, to access a particular element node

 


package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){

        var items:XML = <items>
                          <item>
                            <name>Apple</name>
                            <color>red</color>
                          </item>
                          <item>
                            <name>Orange</name>
                            <color>orange</color>
                          </item>
                        </items>;
                        
        
        trace( items.item[0].name );
        
        trace( items.item[1].name );
    }
  }
}

        








Related examples in the same category

1.Build a property name and, consequently, an element name, dynamically
2.Bracket syntax is required for illegal property name
3.Adding Text Nodes to an XML Object
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