Botones en actionscript 3.0
Tenemos un método crearCirculo al que se le pasa un entero sin signo, y el radio para la creación del círculo, dicho método devuelve una forma.
Para la creacíon del botón utilizamos la clase SimpleButton y creamos una instancia de dicha clase
var boton:SimpleButton = new SimpleButton();
El botón se asocia a diferentes formas según su estado y se establece el area activa del botón a un estado inicial, finalmente se vincula el botón a un evento del mouse.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | package { import flash.display.SimpleButton; import flash.display.Sprite; import flash.events.MouseEvent; import flash.display.Shape; /** * ... * @author DefaultUser (Tools -> Custom Arguments...) */ public class Botones extends Sprite { //creamos un simple boton public function Botones() {var boton:SimpleButton = new SimpleButton(); boton.x = 20; boton.y = 20; boton.upState = crearCirculo(0xFFF000, 15); boton.overState = crearCirculo (0x00ff00,12); boton.downState = crearCirculo (0xCCCCFF, 12); boton.hitTestState = boton.upState; addChild(boton); boton.addEventListener(MouseEvent.CLICK, funcion); } private function funcion (event:MouseEvent):void { trace("pulsado"); } private function crearCirculo(color:uint, radio:Number ):Shape { var forma:Shape = new Shape(); forma.graphics.beginFill(color); forma.graphics.drawCircle(20, 0, radio); forma.graphics.endFill(); return forma; } } } |