Need help writing cleaner version of this array of buttons

Hi there,

not sure how difficult this is going to be, but I have 30 movie clips, which will all be sequentially numbered. (pos1, pos2, pos3…pos30).

They will all have the same functions, with the only change being the number.

I know there is a more efficient way to write this code using arrays, but I will need help with it. I would rather have 10 lines of code than 150.

I also need help with writing the code, that will disable all other movie clips, once the first one is clicked.

Also, not sure how tricky the javascript part will be.

Below is the code i am trying to achieve, but the long version.


pos1.onRelease=function(){
    this.gotoAndStop("selected");        
    getURL("javascript:JSposition('',1)");
    (all other buttons).enabled = false;
}

pos2.onRelease=function(){
    this.gotoAndStop("selected");        
    getURL("javascript:JSposition('',2)");
    (all other buttons).enabled = false;
}

pos3.onRelease=function(){
    this.gotoAndStop("selected");        
    getURL("javascript:JSposition('',3)");
    (all other buttons).enabled = false;
}

pos4.onRelease=function(){
    this.gotoAndStop("selected");        
    getURL("javascript:JSposition('',4)");
    (all other buttons).enabled = false;
}

... all the way to 

pos30.onRelease=function(){
    this.gotoAndStop("selected");        
    getURL("javascript:JSposition('',30)");
    (all other buttons).enabled = false;
}


AS Guru’s please help!!!
Thanks.

Here’s one solution.

Cheers (-:


var nButtons:Number = 30;
function callJavascript():Void {
	var methodName:String;
	var i:Number;
	var n:Number;
	var args:Array = new Array();
	n = arguments.length;
	for (i=0; i<n; ++i) {
		args.push(arguments*);
	}
	methodName = args.splice(0, 1).toString();
	getURL("javascript:"+methodName+"('"+args.join("','")+"');");
}
function init():Void {
	var i:Number;
	var bt:MovieClip;
	for (i=1; i<=nButtons; ++i) {
		bt = this["pos"+i];
		bt.id = i;
		bt.onRelease = function() {
			this.gotoAndStop("selected");
			disableButtons(this.id);
			callJavascript("JSposition", "", this.id);
		};
	}
}
function disableButtons(id:Number):Void {
	var i:Number;
	for (i=1; i<=nButtons; ++i) {
		var bt = this["pos"+i];
		bt.enabled = id == i;
	}
}
//
init();