我需要一个AS3函数来检查我是否单击了Text字段

时间:2014-03-08 21:04:07

标签: actionscript-3 actionscript

我的目标是:

  • 当我点击舞台时,文字字段功能正常。
  • 但我点击没有文字字段的舞台做其他功能。

1 个答案:

答案 0 :(得分:0)

订阅阶段点击事件,并检查target是否为TextField

private function setup():void {
    //For testing, some textField
    _textField = new TextField();
    _textField.text = "Some text here";
    _textField.x = _textField.y = 100;
    stage.addChild(_textField);
    //Your Event Listener
    stage.addEventListener(MouseEvent.CLICK, onClick);
}

private function onClick(e:MouseEvent):void {
    if (e.target == _textField) {
        trace("Clicked TextField");
    } else {
        trace("Clicked Somewhere");
    }
}