views:

17

answers:

1

Hi Everyone,

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!

A: 

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.

gmale