XML gallery with numbers for navigation

Hi Everyone!

I am new to AS 2 and am struggling to make my file work, and I was hoping someone could help me to solve this problem.

I am developing a XML photo gallery and I wanted to create this numbering navigation to change the images. After days combining files together from kirupa tutorials and intensive thinking I got it to work, the problem is it doesn’t quite work as I needed! If you open the attached fla file you’ll see the problem. I needed a function that enables the next and previous button to work, to be executed when the file is initiated, and right now it only works when I press a button from the number navigation.

I tried to comment the file as best as I could so you can understand what I did. I am sure I didn’t put it together the way it’s supposed to be done, but as I said, this file is a result of a combination of other scripts that did complete different things…

Thanks in advance for any help!

You can download the FLA file from here:

http://enemeth.com/ciano/xmltest.fla

And the XML file from here:

http://enemeth.com/ciano/booksXML.xml

Here is the AS:

///////////////////////////////////////////////

[FONT=Courier New]var item_spacing = 20;// how far menu items are spaced veritcally
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&lt;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&lt;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&lt;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&lt;(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&gt;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);
        }
    }
}

}[/FONT]