A menu with loops, arrays, and MADNESS [CS4, AS2.0]

NOTE: Actually CS3, not 4. Can’t edit title.

So I’m working on this menu. Basically, it’s a scrolling list with a series of movieclips within it which are each different items. When you click one of the items, that movieclip that you have clicked runs a little function which tells it to move 10 pixels to the right smoothly. It also checks to see if any of the other movieclips have been previously selected, and if they have, it runs a function that tells them to move back 10 pixels to the left.

So here’s the code I wrote:


_root.graphicsMenuSelect = 0;

graphicsMenuArray = [GraphicsMenu.main.GraphicsMenu0, GraphicsMenu.main.GraphicsMenu1, GraphicsMenu.main.GraphicsMenu2, GraphicsMenu.main.GraphicsMenu3, GraphicsMenu.main.GraphicsMenu4, GraphicsMenu.main.GraphicsMenu5,
GraphicsMenu.main.GraphicsMenu6, GraphicsMenu.main.GraphicsMenu7, GraphicsMenu.main.GraphicsMenu8, GraphicsMenu.main.GraphicsMenu9, GraphicsMenu.main.GraphicsMenu10,
GraphicsMenu.main.GraphicsMenu11, GraphicsMenu.main.GraphicsMenu12, GraphicsMenu.main.GraphicsMenu13, GraphicsMenu.main.GraphicsMenu14, GraphicsMenu.main.GraphicsMenu15];

for(var n:Number=0;i<=graphicsMenuArray.length;i++){
    graphicsMenuArray[n].onRelease = function(){
        _root.graphicsMenuSelect = n;
        if (_root.graphicsMenuSelect == n){
            if (graphicsMenuArray[n]._x == 0){
                graphicsMenuArray[n].moveRight;
            }
            else {
                graphicsMenuArray[n].selectedMenu;
            };
        }
        else {
            if (graphicsMenuArray[n]._x == 10){
                graphicsMenuArray[n].moveLeft;
            }
            else{
                graphicsMenuArray[n].unselectedMenu;
            };
        };
    }
};

An explanation:
_root.graphicsMenuSelect is a variable which determines which of the menu items has been selected. It starts out with 0 being selected.

All of the items in the array are movieclips located in GraphicsMenu.main from where this code is being run. GraphicsMenu is the menu, within that, main is the movieclilp that scrolls.

The line I put ** on is one that I am sure contains part of my problem. I am trying to get it to say “whichever one has been clicked on, set _root.graphicsMenuSelect equal to its number in the array”

Then, if graphicsMenuSelect does equal what has been selected and the item hasn’t been selected (hence, the x value is 0), it tells it to moveRight. If it has already been selected and the person happens to be clicking it again, it will just recognize that it is already selected, just telling its x value to remain at 10.

If graphicsMenuSelect does NOT equal what has been selected, it checks to see if it has already been selected. If it has, and the x value is 10, it will moveLeft. If it hasn’t been selected, the x value is already 0 and it will just remain at 0.

What is currently happening is the loop is freezing up flash, it asks to abort the script. I know that part of my problem is that I can’t figure out how to tell it that I want it to set _root.graphicsMenuSelect to the one that has been clicked.

How can I do that? And what else am I doing wrong?