2011-08-10 171 views
0

我創建動作腳本鍵盤觸摸屏。 我從A按鈕 - Z.ActionScript 3的屏幕鍵盤

我如何獲得價值了鼠標事件的?

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

function keyPressed(e:MouseEvent):void { 

    trace("clicked " + value??); 

} 

回答

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); 
    } 
}