Recipe 19.16 Using XML Data to Initialize a Movie

19.16.1 Problem

You want to use XML data from an external source to initialize certain elements of your Flash movie.

19.16.2 Solution

Use the XML.load( ) method to load the XML data, and then initialize the movie's elements within the onLoad( ) method.

19.16.3 Discussion

One of the many uses for XML within your Flash movie is initializing elements such as menus, navigation elements, news, headlines, and so on. By loading the data from an external source, you can more easily update the values or even generate them from a database. This is extremely important for applications in which the content changes frequently, such as product catalogs, news sites, and message boards. To initialize your movie using XML data, load the data using the XML.load( ) method, and then perform the initialization within the onLoad( ) method (or within a function called by onLoad( )):

my_xml = new XML(  );
my_xml.onLoad = function (  ) {
  /* This example populates a list box with message titles and  
     IDs from XML data that might look something like this:
         <title>XML fun</title>
         <title>more XML fun</title>
         <title>XML fun yet</title>
  var messages = this.firstChild.childNodes;
  for (var i = 0; i < messages.length; i++) {

19.16.4 See Also

See Recipe 16.1 for information on using local shared objects to store client-side information between sessions.

    Part I: Local Recipes
    Part II: Remote Recipes