TLFTextField 的焦点移出事件

发布于 2024-09-09 04:22:32 字数 808 浏览 3 评论 0原文

我遇到一个问题,当我在舞台周围单击时,没有调用“FOCUS_OUT”事件。当我单击 TLFTextField 时,我确实收到了“FOCUS_IN”事件。不确定问题是什么,任何提示或想法都会很棒。我已经做了一些谷歌搜索,但没有找到任何有用的东西。

这是我的一些代码:

txt_search.addEventListener(FocusEvent.FOCUS_IN, onFocusIn);
txt_search.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);

private function onFocusOut(e:FocusEvent):void
    {
        trace("--Search Field-- :: FocusOut");
        if(txt_search.text == '')
        {
            txt_search.text = _defaultText;
        }
        else
        {
            //do nothing
        }
    }

private function onMouseEvent(e:MouseEvent):void
{
    if(txt_search.text != '' && txt_search.text != _defaultText)
    {
        //do search
        trace("--Search Feeds--");
    }
    else
    {
        //do nothing
    }
}

谢谢!

I'm having an issue where I don't get a "FOCUS_OUT" event called when I click around the stage. I do get the "FOCUS_IN" event when I click the TLFTextField. Not sure what the problem may be, any hints or ideas would be great. I did already do some Google searches, but didnt quite find anything useful.

Here is some of the code I have:

txt_search.addEventListener(FocusEvent.FOCUS_IN, onFocusIn);
txt_search.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);

private function onFocusOut(e:FocusEvent):void
    {
        trace("--Search Field-- :: FocusOut");
        if(txt_search.text == '')
        {
            txt_search.text = _defaultText;
        }
        else
        {
            //do nothing
        }
    }

private function onMouseEvent(e:MouseEvent):void
{
    if(txt_search.text != '' && txt_search.text != _defaultText)
    {
        //do search
        trace("--Search Feeds--");
    }
    else
    {
        //do nothing
    }
}

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尹雨沫 2024-09-16 04:22:32

首先,我建议尝试使用所有这四个

txt_search.addEventListener(FocusEvent.FOCUS_IN, inHandler);
txt_search.addEventListener(FocusEvent.FOCUS_OUT, outHandler);
txt_search.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeHandler);
txt_search.addEventListener(FocusEvent.MOUSE_FOCUS_CHANGE, mouseFocusChangeHandler);

然后,您始终可以通过在其他地方添加侦听器来解决焦点事件等事件。例如,如果焦点在一个对象上IN,则意味着它在所有其他对象上OUT。当我写这样的东西时,我有时会使用这个事实。通常,我可以只使用一个事件或另一个事件来逃脱惩罚。您可能不需要两者。

First, I suggest, try playing around with all four of these

txt_search.addEventListener(FocusEvent.FOCUS_IN, inHandler);
txt_search.addEventListener(FocusEvent.FOCUS_OUT, outHandler);
txt_search.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeHandler);
txt_search.addEventListener(FocusEvent.MOUSE_FOCUS_CHANGE, mouseFocusChangeHandler);

Then, you can always work around events like focus events by adding listeners elsewhere. For instance, if the focus is IN on one object, that means it's OUT on all others. I use that fact sometimes when I'm writing things like this. Often, I can get away with using only one event or the other. You may not need both.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文