【问题标题】:Flex 3 focusManager.getNextFocusManagerComponent() returns nullFlex 3 focusManager.getNextFocusManagerComponent() 返回 null
【发布时间】:2010-11-07 22:36:08
【问题描述】:

我有一个应用程序,我希望在其中使 Enter 键像 Tab 键一样。我可以轻松地将按键事件和 setFocus 捕获到文本输入字段。问题在于确定要关注哪个文本输入字段。我有这个代码


trace(this.window.focusManager);
//returns TheWindow86.focusManager

trace(this.window.focusManager.getNextFocusManagerComponent());
//returns null

//This is what I was hoping would work
this.window.focusManager.getNextFocusManagerComponent().setFocus();

代码位于控制器类中,“this.window”引用了 nativeWindow mxml 文件“TheWindow.mxml”的实例。第一个跟踪按预期工作,但第二个跟踪为空。最后一行是我想要工作的代码。

【问题讨论】:

  • 你的“窗口”里面有什么?有没有可聚焦的控件?
  • 它有 20 - 30 个文本框和按钮。我什至从文本框按键事件中调用该函数。

标签: apache-flex actionscript-3 flex3 air


【解决方案1】:

你可以试试:

this.window.focusManager.setFocus(this.window.focusManager.getNextFocusManagerComponent());

希望它有效...如果不让我知道,我会在 flex builder 中尝试!

【讨论】:

  • 和以前一样的错误。 TypeError:错误 #1009:无法访问空对象引用的属性或方法。
【解决方案2】:

这似乎是一个错误。我观察到它发生在设置了 defaultButtons 的表单周围。

【讨论】:

    【解决方案3】:
    focusManager.moveFocus(mx.events.FocusRequestDirection.FORWARD);
    

    如果 focusManager 是 mx.core.Application 的属性,则效果很好

    【讨论】:

      【解决方案4】:

      我也遇到了同样的问题。 很明显——this.window.focusManager.getNextFocusManagerComponent().setFocus(); - 给你一个错误,因为 - this.window.focusManager.getNextFocusManagerComponent() - 返回 null。

      我不明白为什么 focusManager 不知道接下来会出现什么组件……有问题。

      【讨论】:

      • 这就是我得出的结论。 focusManager 的行为就像它不知道组件的顺序一样。
      【解决方案5】:

      focusManager.moveFocus(FocusRequestDirection.FORWARD);

      试试看;

      【讨论】:

      • 这是我没试过的。虽然仍然得到同样的错误。 TypeError:错误 #1009:无法访问空对象引用的属性或方法。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多