【问题标题】:Flex 4.5 - Custom NativeWindow and problemsFlex 4.5 - 自定义 NativeWindow 和问题
【发布时间】:2011-08-10 13:14:32
【问题描述】:

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

例如焦点围绕文本输入不可见。 向下和向上键在 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;


        }
    }
}

【问题讨论】:

  • 添加自己的WindowedSystemManager(并添加到舞台)的目的是什么?我认为这可能会干扰 Flex 创建的那个。

标签: apache-flex actionscript-3 air


【解决方案1】:

您应该在FlexNativeWindow 中实现IFocusManagerContainer 以解决焦点问题。

这是在 Flash Builder 中的操作方法:

  1. Ctrl + Shift + T 并输入IFocusManagerContainer
  2. 打开对应文件
  3. 在你的类中实现所有声明的方法FlexNativeWindow

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

【讨论】:

  • 感谢您的回答。作为初学者,你能解释一下如何修改 FlexNativeWindow 类/谢谢
  • 感谢您的回答。我做了你解释的,但只有 get 和 set DefaultButton。
  • 感谢您的回答。我做了你解释但只有get和set DefaultButton。是否有必要实现所有声明的方法。其他问题,我使用 NativeWindow 是因为我使用空气,并且使用本机窗口选项对我来说很重要。因此,如果可以使用窗口进行销售,我将很高兴知道如何。谢谢
  • 您可以将defaultButton 实现为始终返回null 的空属性。我认为可以在NativeWindow 子类中重新实现 Flex 容器逻辑,但是我无法想象需要这样做的任务。请告诉我们您为什么要这样做?
猜你喜欢
  • 2010-11-14
  • 2011-01-16
  • 2012-02-23
  • 1970-01-01
  • 2012-04-18
  • 1970-01-01
  • 2011-12-22
  • 2011-08-03
  • 1970-01-01
相关资源
最近更新 更多