SwitchButton.as

by LĂșcio on July 4th, 2009
No notes
Syntax: ActionScript 3
Show lines - Hide lines - Show in textbox - Download
package
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
 
	public class SwitchButton extends MovieClip
	{		
		public function SwitchButton()
		{
			changeState("off");
			ButtonsControl.addButton(this);
		}
 
		internal function changeState(state:String):void
		{
			this.gotoAndStop(state);
 
			if(state == "off")
			{
				this.addEventListener(MouseEvent.MOUSE_DOWN, turnOnOff);
				this.buttonMode = true;
			}
			else
			{
				this.removeEventListener(MouseEvent.MOUSE_DOWN, turnOnOff);
				this.buttonMode = false;
			}
		}
 
		private function turnOnOff(e:MouseEvent):void
		{
			ButtonsControl.commute(this);
		}
	}
}

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS