一千萬個為什麽

搜索

Flex:失去組件焦點

我有一個(希望)快速的問題。我有一些步進盒。雖然這確實適用於任何交互式組件。當我點擊其他任何地方時(包括舞臺),我希望所選的框失去焦點。是否有捷徑可尋?我似乎無法找到一種讓它失去焦點的有效方法。

最佳答案

如果其他人找到他們的方式來尋求解決這個問題,這裏的答案是:

private function onGlobalMouseUp(event : MouseEvent) : void {
        var fm:FocusManager = new FocusManager(stage);

        //Since Flash Player can set focus on subcomponents as well as on components themselves, 
        //findFocusManagerComponent is used to find the component that either has focus or contains the subcomponent 
        //that has focus. If, for example, a TextField contained within a TextArea component has focus, findFocusManagerComponent 
        //will return the TextArea component, and not the TextField.  This being the case, we can definitely determine 
        //whether the target object of the MouseUp event is a component (or is part of a component).  If the target
        //object is NOT a component (nor contained within one), then we clear all component focus.

        if(fm.findFocusManagerComponent(event.target as InteractiveObject) is UIComponent){
            //target of MouseUp is either a UIComponent, or is contained within a UIComponent, so do nothing.
        }else{
             //target of MouseUp is neither a UIComponent, nor is it contained within a UIComponent, so set component focus to null.
            fm.setFocus(null);
        }
    }

轉載註明原文: Flex:失去組件焦點