How to execute a function on XML load

Hi Guys,

I am struggling trying to put together two or three tutorials in order to make a photo gallery with numbers as the navigation to work. I am almost there, the problem is that in addition to the numbers as navigation I also wanted to have the option to change the images using a previous and next button. Here is a link of what I am trying to do:

http://enemeth.com/flashTest/xmltest.html

The reason the previous and next buttons don’t work is because their functions are within a main function that is called onRelease of one the number buttons. Once you click the numbers, the previous and next start to work.

My question would be if there is a way to auto execute the function DisplayInfo as the XML file loads. See code Below:



var item_spacing = 20;// how far menu items are spaced vertically
var item_count = 0;// counts menu items as they are added from the XML


function loadXML(loaded) {
    if (loaded) {
        xmlNode = this.firstChild;
        identity = [];
        description = [];
        total = xmlNode.childNodes.length;
        for (i=0; i<total; i++) {
            // extract content from XML file
            identity* = xmlNode.childNodes*.childNodes[1].firstChild.nodeValue;
            description* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;

            // load menu item movie clips, creating the navigation numbers
            var item_mc = menu_mc.attachMovie("menu_item", "item"+item_count, item_count);
            item_mc._x = item_count*item_spacing;
            item_count++;

            // assign navigation numbers
            item_mc.species_txt.text = i+1;
            
/*****************************************************************************/
//I don't quite understand what is "location_text". I know that I used it down on the DisplayInfo function.

            item_mc.main_btn.location_text = description*;
            item_mc.main_btn.location1_text = identity*;
            
/*****************************************************************************/
                                    
                                    
//********** Somehow I needed to execute the function DisplayInfo when the file is initiated with same paramenter as 
//             the onRelease button as below ***********
                                    
            // set the onRelease of the item button to the DisplayInfo function
            menu_mc['item'+i].main_btn.onRelease = DisplayInfo;
            
            // set all numbers to default color
            item_mc.main_btn.onPress = function() {
                for (e=0; e<total; e++) {
                    format = new TextFormat();
                    format.color = 0x999999;
                    menu_mc['item'+e].species_txt.setTextFormat(format);
                }
            };
            
        }
        firstImage();
                
    } else {
        content = "file not loaded!";
    }
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("booksXML.xml");


/////////////////////Functions//////////////////////


//This function is bringing the inital values to text fields on the file initiation, it doesn't execute displayInfo function!
function firstImage() {

    if (loaded == filesize) {
        p = 0;
        desc_txt.text = description[p];
        id_txt.text = identity[p]+"/" +total;
        
        //Assigns the highlight color to number 1
        format = new TextFormat();
        format.color = 0xFF3366;
        format.bold = true;
        menu_mc['item'+0].species_txt.setTextFormat(format);
        }
}


//This function, once first executed by pressing main_btn, manages the number navigation and previous and next buttons.
function DisplayInfo() {
    
    var idNumber = this.location1_text;
    var select = idNumber-1;
//    trace(select);
    
    
    //Assigns xml value from XML file to text field
    desc_txt.text = description[select];
    
    //Assigns values to id_txt 1/10
    id_txt.text = select+1 +"/" +total;
    
    
    //Assigns the highlight color to the actual number
    format = new TextFormat();
    format.color = 0xFF3366;
    format.bold = true;
    menu_mc['item'+select].species_txt.setTextFormat(format);



/////////////////Previous and Next Buttons///////////////
    
    
    // set all numbers to default color onPress of previous and next Buttons
    next_btn.onPress = function() {
        if (select+1 != total) {
            for (e=0; e<total; e++) {
                format = new TextFormat();
                format.color = 0x999999;
                menu_mc['item'+e].species_txt.setTextFormat(format);
            }
        }
    };
    previous_btn.onPress = function() {
        if (select != 0) {
            for (e=0; e<total; e++) {
                format = new TextFormat();
                format.color = 0x999999;
                menu_mc['item'+e].species_txt.setTextFormat(format);
            }
        }
    };

    // sets onRealese the previous and next functions
    next_btn.onRelease = function() {
        nextImage();
    };

    previous_btn.onRelease = function() {
        prevImage();
    };
    
    // previous and next functions
    function nextImage() {
        if (select<(total-1)) {
            select++;
            if (loaded == filesize) {
                desc_txt.text = description[select];    //ressigns xml value from XML file to text field   
                id_txt.text = identity[select]+"/" +total;  //reassigns values to id_txt 1/10, once previous button is pressed
                
                //reassigns the highlight color to the actual number, once next button is pressed
                format = new TextFormat();
                format.color = 0xFF3366;
                format.bold = true;
                menu_mc['item'+select].species_txt.setTextFormat(format);
            }
        }
    }
    function prevImage() {
        if (select>0) {
            select--;
            if (loaded == filesize) {
                desc_txt.text = description[select];    //ressigns xml value from XML file to text field 
                id_txt.text = identity[select]+"/" +total;    //reassigns values to id_txt 1/10, once previous button is pressed
                
                //reassigns the highlight color to the actual number, once previous button is pressed
                format = new TextFormat();
                format.color = 0xFF3366;
                format.bold = true;
                menu_mc['item'+select].species_txt.setTextFormat(format);
            }
        }
    }
}