How can i add additional functionality to this code

Hi all

I hope i can describe this problem in as plain a way a possible.

I am attempting to make a small gallery of pictures that slide in from the right when i press the relevent button - which functions perfectly as it stands, here’s the code structure on the main timelines ‘actions’ layer, but1, but2 etc are actual buttons and not MC’s:

[COLOR=“Blue”]// _root.imagewidth defines the width of the image//
_root.imagewidth = 385;

// _root.speed defines the speed of the sliding images//
_root.speed = 3;

/* _root.trig.xposnew defines the x position of the
sliding images */
_root.trig.xposnew = -(_root.imagewidth);

// About us Button
but1.onRelease = function() {
_root.trig.xposnew = -(_root.imagewidth);
}
// Products Button
but2.onRelease = function() {
_root.trig.xposnew = -((_root.imagewidth)*2);

}
// Services Button
but3.onRelease = function() {
_root.trig.xposnew = -((_root.imagewidth)*3);
};
[/COLOR]
e.t.c

First step i made was to make up the buttons using MC’s instead of actual button symbols.
My first problem was that not only did i want ‘selected’,‘deselected’ and rollover states, but i also wanted to achieve it with tidier code done in a more ‘modular’ fashion.
Any other ‘button’ states would have to have involved long lines of repeated code for each button - like so…

[COLOR=“Blue”]but1.onRelease = function() {
_root.trig.xposnew = -(_root.imagewidth);
}
but1.onRollOver = function() {
but1.gotoAndStop(“selected”);
}
but1.onRollOut = function() {
but1.gotoAndStop(“deSelected”);
}[/COLOR]

I found a more ‘modular’ way of tackling the button state problem on the net which i thought was most elegant (i altered the original to include my MC buttons):

[COLOR=“DarkRed”]var buttonNames_array:Array = [but1, but2, but3, but4, but5, but6, but7, but8, but9, but10];
var currentlySelectedButtonID:Number;
clearAllButtons = function () {
for (var i = 0; i<buttonNames_array.length; i++) {
if (i != currentlySelectedButtonID) {
buttonNames_array*.gotoAndStop(“deselected”);
}
}
};

buttonRollOver = function () {
clearAllButtons();
if (currentlySelectedButtonID != this.id) {
this.gotoAndStop(“rollOver”);
}
};
buttonRollOut = function () {
clearAllButtons();
};

buttonOnRelease = function () {
currentlySelectedButtonID = this.id;
clearAllButtons();
this.gotoAndStop(“selected”);
};

for (i=0; i<buttonNames_array.length; i++) {
buttonNames_array*.id = i;
buttonNames_array*.onRollOver = buttonRollOver;
buttonNames_array*.onRollOut = buttonRollOut;
buttonNames_array*.onRelease = buttonOnRelease;
}
[/COLOR]
only problem now is how do i incorporate my “[COLOR=“Blue”]_root.trig.xposnew = -(_root.imagewidth);[/COLOR]”
into the structure above.

The main obsticle as i see it is.

1: how to set it up so the numerical value of buttonNames_array* can be appended on the end of (_root.imagewidth)*, so as to add the revelvant number depending on the button pressed, so returning these values when pressing but1, but2 and but3:

[COLOR=“DeepSkyBlue”]_root.trig.xposnew = -((_root.imagewidth);
_root.trig.xposnew = -((_root.imagewidth)*2);
_root.trig.xposnew = -((_root.imagewidth)*3);
[/COLOR]
Am i correct in this assumption? or is there a much simpler answer this?

i’ve rack my primative brain trying to figure it out but i have nomore hair to pull out.

i dearly hope that made sense

thanx to all that can help