I am creating an action script keyboard for a touch screen. I have buttons from A - Z.
How do I get开发者_如何学JAVA the value out of the mouse event?
Q.addEventListener(MouseEvent.MOUSE_DOWN, keyPressed);
W.addEventListener(MouseEvent.MOUSE_DOWN, keyPressed);
function keyPressed(e:MouseEvent):void {
trace("clicked " + value??);
}
You can create a class KeySprite which has a variable value and the key should be KeySprite :
public class KeySprite extands Sprite {
public var value:String;
public function KeySprite (value:String){
this.value = value;
}
}
And the event catch will be :
function keyPressed(e:MouseEvent):void {
if(e.currentTarget is KeySprite){
var currentKey:KeySprite = (KeySprite)e.currentTarget;
trace("clicked " + currentKey.value);
}
}
精彩评论