Actionscript 3屏幕键盘

时间:2011-08-10 13:20:25

标签: actionscript-3 keyboard

我正在为触摸屏创建一个动作脚本键盘。 我有A - Z的按钮。

如何从鼠标事件中获取值?

Q.addEventListener(MouseEvent.MOUSE_DOWN, keyPressed);
W.addEventListener(MouseEvent.MOUSE_DOWN, keyPressed);

function keyPressed(e:MouseEvent):void {

    trace("clicked " + value??);

}

1 个答案:

答案 0 :(得分:1)

您可以创建一个KeySprite类,它具有一个变量值,键应该是KeySprite:

public class KeySprite extands Sprite {

    public var value:String;

    public function KeySprite (value:String){
        this.value = value;
    }
} 

事件捕获将是:

function keyPressed(e:MouseEvent):void {
    if(e.currentTarget is KeySprite){
        var currentKey:KeySprite = (KeySprite)e.currentTarget;
        trace("clicked " + currentKey.value);
    }
}