Basically, I want a group of buttons in which only one (the one you last clicked) can be on at a time.
What is the easiest way to do this?
Currently, this is the fastest way I can find, and I'm sure it isn't the fastest way.
Code:package { import flash.events.*; import flash.display.MovieClip; public class Fasdfs extends MovieClip { var buttonArr:Array; var i:int; public function Fasdfs() { buttonArr = new Array(5); buttonArr[0] = but0; buttonArr[1] = but1; buttonArr[2] = but2; buttonArr[3] = but3; buttonArr[4] = but4; for (i = 0;i < buttonArr.length;i++) { buttonArr[i].addEventListener(MouseEvent.CLICK,clicked1); } } function clicked1(e:MouseEvent):void { if (e.target.isOn) { for (i = 0;i < buttonArr.length;i++) { if (buttonArr[i] != e.target) { buttonArr[i].gotoAndStop(1); } } } } } }All the buttons on the stage have the SelectButton baseclass. GotoAndStop is there because each button (but0, but1, but2, etc) has a yellow frame and black frame, to visually show toggling.Code:package { import flash.events.*; import flash.display.MovieClip; public class SelectButton extends MovieClip { public var isOn:Boolean; public function SelectButton() { isOn = false; this.addEventListener(MouseEvent.CLICK,clicked); } function clicked(e:MouseEvent):void { isOn = true; this.gotoAndStop(2); } } }
Got a quicker solution?




Reply With Quote