Flex 4.5 - 自定义NativeWindow和问题

时间:2011-08-10 13:14:33

标签: flex actionscript-3 air

我有一个扩展到NativeWindow的FlexNativeWindow类。 我使用此方法在AIR应用程序上创建新窗口。 一切运作良好,但有些键盘交互不可用。

例如,焦点arround textinput不可见。 键向下和向上不适用于DropDownList。 TabOrder效果不佳!

你能解释一下为什么吗?因为我非常沮丧!

创建新窗口的代码

var wdetcorr:wDetailCorrespondant = new wDetailCorrespondant();
                wdetcorr.monIdCorresp = correspDG.selectedItem.crIndex;

                var wOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
                wOptions.systemChrome = NativeWindowSystemChrome.NONE;
                wOptions.transparent = false;
                var fnwDetailPatient:FlexNativeWindow = new FlexNativeWindow(wdetcorr, wOptions);
                fnwDetailPatient.active();

关于我的自定义NativeWindow的代码

package fr.int.ui.windowSkin
{
    import flash.display.NativeWindow;
    import flash.display.NativeWindowInitOptions;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;

    import mx.core.IUIComponent;
    import mx.core.IVisualElement;
    import mx.core.IVisualElementContainer;
    import mx.core.UIComponent;
    import mx.events.*;
    import mx.managers.WindowedSystemManager;

    [Event(name="creationComplete", type="mx.events.FlexEvent")]

    public class FlexNativeWindow extends NativeWindow implements IFlexNativeWindow
    {
        private var _systemManager:WindowedSystemManager;

        private var _content:UIComponent;

        private var _window:IVisualElementContainer;

        public function FlexNativeWindow(window:IVisualElementContainer, initOptions:NativeWindowInitOptions = null)
        {
            super(initOptions);


            _window = window;

            addEventListener(Event.ACTIVATE, windowActivateHandler);

        }

        public function addElement(control:IVisualElement):void
        {
            _window.addElement(control);
        }

        public function removeElement(control:IVisualElement):void
        {
            _window.removeElement(control);
        }

        private function windowActivateHandler(event:Event):void
        {
            event.preventDefault();
            event.stopImmediatePropagation();
            removeEventListener(Event.ACTIVATE, windowActivateHandler);

            if (stage)
            {
                if (!_systemManager)
                    _systemManager = new WindowedSystemManager(IUIComponent(_window));

                stage.addChild(_systemManager);

                dispatchEvent(new FlexEvent(FlexEvent.CREATION_COMPLETE));

                stage.addEventListener(Event.RESIZE, windowResizeHandler);
                stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);

            }
        }

        private function keyDownListener (e:KeyboardEvent):void {

            if (e.keyCode == Keyboard.ESCAPE) {
                stage.nativeWindow.dispatchEvent(new Event("myEventClose", true));
                stage.nativeWindow.close();
            }


        }

        private function windowResizeHandler(event:Event):void
        {
            // prise en compte de la valeur mini
            UIComponent(_window).height = stage.stageHeight;
            UIComponent(_window).width = stage.stageWidth;


        }
    }
}

1 个答案:

答案 0 :(得分:0)

您应该在IFocusManagerContainer中实施FlexNativeWindow来解决焦点问题。

以下是在Flash Builder中执行此操作的方法:

  1. Ctrl + Shift + T并输入IFocusManagerContainer
  2. 打开相应的文件
  3. 在您的班级FlexNativeWindow
  4. 中实施所有声明的方法

    P.S:但是这种方法可能会失败,因为flex组件应该放在flex容器中,而NativeWindow是本机类,而不是Flex SDK类。我建议你使用Window类作为Flex容器,并且已经实现了IFocusManagerContainer