This program reads in a list of words from an XML file, and then parses through them, displaying the appropriate letter and then   XML is a file type that is versatile in its application and implementation.  Basically, an XML file is a tree.  Here is an example.

<?xml version="1.0" encoding="utf-8"?>
<Strings>
    <STRING DATUM = "godfather"/>
    <STRING DATUM = "genius"/>
    <STRING DATUM = "mystery"/>
    <STRING DATUM = "southwest"/>
    <STRING DATUM = "police"/>
    <STRING DATUM = "genuine"/>
    <STRING DATUM = "climber"/>
    <STRING DATUM = "clobber"/>
    <STRING DATUM = "batman"/>
    <STRING DATUM ="unicycle"/>
</Strings>

This is a list of strings, a simple document.  Each string is contained in a node of type STRING with an attribute of DATUM, which is the individual string (i.e. godfather – unicycle).


This next function is an XML parser that will parse through an XML file and place the string datums within an array.  First, import the appropriate library functions needed.  The private variables are the array into which we will place the strings, the XMLList we will get from the XML flie, and my_total, which is the total number of elements in the array.

We have several functions local to the this function; these are used only within the this function and do not need to be accessed by any outside client.  First, declare and initialize the URLLoader.  This will allow us to load an external file into our program.  Next, attach an eventlistener to the loader, listening for its completion.  When the loading is complete, the listener will run the function process XML.  Then load quiz1.xml into the program using the URLLoader and URLRequest.  This will request this file from the source repository and then load it into a data object that is passed on into processXML.

The function processXML converts the data object into an XMLList.
The next function called, callStrings(), iterates through the XMLList and places the DATUM strings into the array, quizArray.
 
          
           //the array to put the quiz words
            var quizArray:Array;
            //load the XML file and place the datums into the above declared array
            makeStringArray();
          

           function makeStringArray():void
           {
                   var my_strings:XMLList;
                var my_total:Number;
              
                   var myXMLLoader:URLLoader = new URLLoader();
                myXMLLoader.addEventListener(Event.COMPLETE, processXML);
                myXMLLoader.load(new URLRequest("christmas.xml"));
              
                    function processXML (e:Event):void{
                     var myXML:XML = new XML(e.target.data);
           
                    my_strings = myXML.STRING;
                    my_total = my_strings.length();
                    quizArray = new Array(my_total);
                    callStrings();
                }
                function callStrings():void{
                    for (var i:Number = 0; i < my_total; i++){
                        var my_string:String = my_strings[i].@DATUM;
                        quizArray[i] = my_strings[i].@DATUM;
                    }
                }
            }