forked from: forked from: forked from: マウスイベントを使ったボタン

by hacker_9p8x8mco forked from forked from: forked from: マウスイベントを使ったボタン (diff: 15)
♥0 | Line 42 | Modified 2010-02-13 13:30:10 | MIT License
play

ActionScript3 source code

/**
 * Copyright hacker_9p8x8mco ( http://wonderfl.net/user/hacker_9p8x8mco )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/8mqV
 */

package{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	public class Ms extends Sprite{
//		private var _button:MyButton;
		public function Ms(){
			var _button:MyButton = new MyButton();
			_button.addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
			_button.addEventListener(MouseEvent.MOUSE_OUT,onMouseOut);
			
			addChild(_button);

			_button.x = 182;
			_button.y = 52;
			
			function onMouseOver(e:MouseEvent):void{
				_button.over();
			}
			function onMouseOut(e:MouseEvent):void{
				_button.out();
			}			
		}

	}
}


import flash.display.Sprite;

class MyButton extends Sprite{
	private var _over:Sprite;
	
	public function MyButton(){
		graphics.beginFill(0x333333);
		graphics.drawRoundRect(0,0,100,22,15);
		graphics.endFill();

		_over = new Sprite();
		_over.graphics.beginFill(0xff0000);
		_over.graphics.drawRoundRect(0,0,100,22,15);
		_over.graphics.endFill();
		_over.visible = false;
		addChild(_over);

		buttonMode = true;
	}

	public function over():void{
		_over.visible = true;
	}

	public function out():void{
		_over.visible = true;
	}
}