En este primer post voy a mostrar el uso basico de Eventos en AS3
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
/**
* ...
* @author EzeQL
* @see WWW.EZEQL.COM/BLOG
*/
public class EventosIntro extends Sprite {
private var _box:Sprite;
private var _tf:TextField;
private var _click:int = 0;
private const VECES_CLICK:String = " veces clickeado";
public function EventosIntro() {
draw();
initListeners();
}
private function draw():void {
_box = new Sprite();
_box.graphics.lineStyle(1, 0);
_box.graphics.beginFill(0xFF0000);
_box.graphics.drawCircle(50, 75, 50);
_box.graphics.endFill();
_box.alpha = 0.4;
addChild(_box);
_tf = new TextField();
_tf.selectable = false;
_tf.textColor = 0x0000ff;
_tf.autoSize = flash.text.TextFieldAutoSize.LEFT;
updateText();
addChild(_tf);
}
private function initListeners():void {
_box.addEventListener(MouseEvent.CLICK, onBoxCLick, false, 0, true);
_box.addEventListener(MouseEvent.MOUSE_OVER, onBoxOver, false, 0, true);
_box.addEventListener(MouseEvent.MOUSE_OUT, onBoxOut, false, 0, true);
}
private function onBoxOut(e:MouseEvent):void {
_box.alpha = .4;
}
private function onBoxOver(e:MouseEvent):void {
_box.alpha = 1;
}
private function onBoxCLick(e:MouseEvent):void {
_click++;
_box.x++;
_box.y++;
updateText();
}
private function updateText():void{
_tf.text = _click.toString() + VECES_CLICK;
}
}
}