Hi!
I’m trying to create a simple map game for an upcoming world scout jamboree and I’m in need of some help. I think that my problem is pretty basic, and I’ll try to explain this as simple as possible;
I’ve created an array of three ‘buttons’. Only one button can be active at a time. I’d like to add a function that deactivates a button if I click it again. I’d also like to create a ‘controller button’ that closes all active buttons. I’ve followed an online tutorial and I’ll attach the source file and actionscript in this message and I’d be very grateful for assistance.
- Johan
/*#######################################################
* Written by: Sorin Haidan
* email: [email protected]
* blog: http://biochimistu.blogspot.com
############################
############################*/
stage.frameRate = 30;
var buttonsArray:Array = [button_1,button_2,button_3];
function setButtons():void {
for (var i:int=0; i<buttonsArray.length; i++) {
buttonsArray*.id = i;
buttonsArray*.buttonMode = true;
buttonsArray*.mouseEnabled = true;
buttonsArray*.addEventListener(MouseEvent.CLICK,doClick);
}
}
function doClick(event:MouseEvent):void{
var currentBtn:int = event.currentTarget.id;
setSelectedBtn(currentBtn);
}
function setSelectedBtn(id:int):void{
for (var i:int=0; i< buttonsArray.length; i++) {
if (id == i) {
buttonsArray*.gotoAndPlay("start");
buttonsArray*.buttonMode = true;
buttonsArray*.mouseEnabled = true;
buttonsArray*.removeEventListener(MouseEvent.CLICK,doClick);
} else {
if(buttonsArray*.currentLabel =="start"){
buttonsArray*.gotoAndPlay("stop");
}
buttonsArray*.buttonMode = true;
buttonsArray*.mouseEnabled = true;
buttonsArray*.addEventListener(MouseEvent.CLICK,doClick);
}
}
}
setButtons();