Using AS3 to parse XML created with php

I need to parse XML that is being dynamically created using php with AS3 so that I can feed the nodes into dynamic text fields on my stage.

I feel like this should be pretty straightforward, but am running into problems where I can’t get flash to talk to my nodes (I get an error where: Error #1034: Type Coercion failed: cannot convert XML@29578251 element <key> to XMLList.) and I have searching for forever to try to figure out how to resolve this. Any suggestions would be greatly appreciated!

//Query string: "*" gets all of the information from all of the columns in the table "contacts". 
    $sql = "SELECT * FROM contacts";
    //The result of the function fetch_all_array is being stored in this variable $family. 
    $contacts = fetch_all_array($sql);


      print "<contacts>";
    foreach($contacts as $person){
        print "<person>";
        //Each person has it's own array. Loop through each set of info inside of person and we are going to grab the key so we know what we're working with (id, name, phone, email, address, notes and photo) as well as the value for that key so that we can create XML nodes with this information. 
        foreach($person as $key=>$val){
            print "<key>$val</key>";
        print "</person>";    
    print "</contacts>";
    //Turn the while loop into a function
    function fetch_all_array($query){
        //Create an array.
        $data = array();
        $result = mysql_query($query);
        //While loop: while there is still more information, continue looping and store this information in $data. We are telling it to fetch this data as an associated array from $result.  
        while ($row = mysql_fetch_assoc($result)) {
            $data[] = $row;
        return $data;


package Classes {
    import flash.display.Sprite;
    import Classes.Utilities.*;            
    public class AddressBook extends Sprite {
        public var loader:URLLoader = new URLLoader();
        public var url:URLRequest = new URLRequest("http://localhost:8888/connectToDB.php");
        //XML variables
        public var xml:XML;
        public var nameList:XMLList;
        public var phoneList:XMLList;
        public var emailList:XMLList;
        public var addressList:XMLList;        
        public var notesList:XMLList;
        public var photoList:XMLList;
        //CONSTRUCTOR CODE        
        public function AddressBook() {
            loader.addEventListener(Event.COMPLETE, loaded);
            loader.addEventListener(IOErrorEvent.IO_ERROR, error);
            //Instantiate buttons
            var c:CreateBtn = new CreateBtn("Create New");
            c.x = 384;
            c.y = 375;
            var d:DeleteBtn = new DeleteBtn("Delete Conact");
            d.x = 482;
            d.y = 375;
            //Custom Event Listeners
            this.addEventListener("createBtnClicked", createBtnClicked);                
        public function loaded(e:Event):void {
            //XML created from connectToDB.php (based on information in the DB). 
            var xml = new XML(;
        public function error(e:IOErrorEvent):void{
        public function parseXML(contactsXML:XML):void {

            XML.ignoreWhitespace = false;                        
            //Define the XML variables that were created above. 
            nameList = contactsXML.person.key[1];
            //For loop to create text fields in ContactHolder_mc
            /*for(var i:int = 0; i<nameList.length(); i++){
                trace("WILL CONTACT FIELD FOR",nameList*);
                //If you want to talk to the class, you must first create a new Thumb. 
                var c:ContactField = new ContactField(i, nameList*);
                addChild(c);    */                    
        public function createBtnClicked(e:CustomEvent):void {
            //Create the SubmitContactHolder that will let us input info for new contacts. 
            var submitContact:SubmitContactHolder = new SubmitContactHolder();
            //Add submitContact to the stage when the CreateBtn is clicked and place it appropriately. 
            submitContact.x = 232;
            submitContact.y = 68;