Use the for..in or for each..in statements to iterate through an XMLList. : loop through « XML « Flash / Flex / ActionScript






Use the for..in or for each..in statements to iterate through an XMLList.

 

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>;
        
        var movies:XMLList = movieList.movie;
        for each (var movie:XML in movies) {
            movie.title = movie.title.toUpperCase();
        }
        trace(movies.title);
        
    }
  }
}

        








Related examples in the same category

1.Processing XML with for-each-in and for-in
2.Use for loop to go through the xml data
3.Accessing Descendants
4.Create Date object from xml data
5.Use for each loop to access the attributes
6.Iterating through the Children of an Element
7.Tree traversal: converts every element and attribute name to lowercase: