Accessing Values with E4X: Using the Dot Operator to Access Elements : Bracket syntax « XML « Flash / Flex / ActionScript






Accessing Values with E4X: Using the Dot Operator to Access Elements

 


package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var movieList:XML = <movieList>
                                <listName>My favorite movies</listName>
                                <movie id="123">
                                    <title>Titus</title>
                                    <year>1999</year>
                                    <director>J T</director>
                                </movie>
                                <movie id="456">
                                    <title>Rushmore</title>
                                    <year>1998</year>
                                    <director>W A</director>
                                </movie>
                                <movie id="789">
                                    <title>Hall</title>
                                    <year>1977</year>
                                    <director>Woody Allen</director>
                                </movie>
                           </movieList>;
        
        trace(movieList.listName); // Displays : My favorite movies
        
        trace(movieList.movie[1]);
        
        trace(movieList.movie[0].title); 
        trace(movieList.movie[2].director);

    }
  }
}

        








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 bracket notation, coupled with an integer, to access a particular element node
5.Use a variable's value as the element name to find:
6.XML text in a String into an actual XML object, whereas a cast would fail.