开发者

Avoid FocusOut event trigerred when apllication loses focus

开发者 https://www.devze.com 2023-01-16 04:20 出处:网络
I have done an override of the standard TextInput component In this component I have : 开发者_如何学GoaddEventListener( FocusEvent.FOCUS_OUT, handleFocusOut );

I have done an override of the standard TextInput component

In this component I have :

开发者_如何学GoaddEventListener( FocusEvent.FOCUS_OUT, handleFocusOut ); 
  • My method is triggered when the field loses focus for another field (nice)
  • Problem : It is triggered also when the whole flex application loses focus (when my field has the current focus inside my form)

Questions :

  • What have I done wrong ?
  • Is there a way to avoid doing stuff when it is a application-focusout-event ?

Regards


I am not sure why this is behaving this way. But one solution might be to have an eventListener for FOCUS_OUT event at the application level and call stopImmediatePropagation().


Thanks for your help !
Here is what I have done in my component (textinput child)

Add two event handler :
- addEventListener( Event.ACTIVATE, handleEventActivate );
- addEventListener( Event.DEACTIVATE, handleEventDeActivate );

They update the internal field _isApplicationActive
I handle the focusOut event :
addEventListener( FocusEvent.FOCUS_OUT, handleFocusOut );
in the method I have
if (!_isApplicationActive) { event.stopImmediatePropagation(); }

With this my focusOut handling functions are not called when the app is deactivated Because => DECACTIVATE events are called before FocusOut events !


The easy answer is to check if event.relatedObject (the object receiving focus) is null. Flex's FocusManager tries really hard to ensure some flex object has (flex) focus, so it should not be null otherwise.

Do also check isRelatedObjectInaccessible if you might need to.

0

精彩评论

暂无评论...
验证码 换一张
取 消