Add mouse click event to SimpleButton
|
package { import flash.display.*; import flash.events.*;
public class SimpleButtonDemo extends Sprite { public function SimpleButtonDemo( ) { var button:SimpleButton = new SimpleButton( ); button.x = 20; button.y = 20; button.upState = createCircle( 0x00FF00, 15 ); button.overState = createCircle( 0xFFFFFF, 16 ); button.downState = createCircle( 0xCCCCCC, 15 );
button.hitTestState = createCircle( 0x000000, 50 ); button.addEventListener( MouseEvent.CLICK, handleClick ); addChild( button ); } private function createCircle( color:uint, radius:Number ):Shape { var circle:Shape = new Shape( ); circle.graphics.lineStyle( 1, 0x000000 ); circle.graphics.beginFill( color ); circle.graphics.drawCircle( 0, 0, radius ); circle.graphics.endFill( ); return circle; } private function handleClick( event:MouseEvent ):void { trace( "Mouse clicked on the button" ); } } }
|
|
|
|
|
Related Scripts with Example Source Code in same category :
-
-
|
|