焦点管理器在Scroller类中的错误 [英] Focus Manager bug in Scroller class

查看:222
本文介绍了焦点管理器在Scroller类中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  TypeError:错误#1009:无法在Scroller.as类行2139中收到以下错误访问空对象引用的属性或方法。 
在spark.components :: Scroller / focusInHandler()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\Scroller.as: 2139]
在flash.display :: Stage / set focus()

从Scroller。作为

  / ** 
* @private
*侦听来自后代的任何focusIn事件
* /
覆盖保护函数focusInHandler(event:FocusEvent):void
{
super.focusInHandler(event);

//当我们获得焦点时,确保焦点元素是可见的
if(viewport&&&& ;ElementIsVisibleForSoftKeyboard)
{
var elt:IVisualElement = focusManager .getFocus()as IVisualElement;
lastFocusedElement = elt;






$ b

由于这是框架代码,我必须要做什么防止它?

上下文
我创建了一个弹出的TitleWindow,添加了一个Module并显示出来。该模块有几个国家,在每个国家是一个集团,一个集团有一个名单,该名单有一个ItemRenderer,该ItemRenderer有一个复选框。

模块也有一个菜单。菜单打开后,弹出的菜单列出了模块可用的状态。当从弹出菜单中选择一个项目时,我切换到另一个状态。

当状态改变,最后一项是复选框时,就会产生错误。至少这就是我所想的事情。我推断这是因为在Scroller类中处理程序正在处理一个事件。在这个事件是目前的目标。当前目标是复选框。

更新 - 重现步骤

  //在Application.mxml里面
//定义变量
public var popup:Group;
public var titleWindow:TitleWindow;


//显示弹出窗口
public function showInspector():void {

//显示检查器方法
//创建新的检查器容器
popup = new InspectorContainer(); //一个组件实现=mx.managers.IFocusManagerContainer
titleWindow = new TitleWindow();
titleWindow.addElement(popup);

//显示弹出窗口标题窗口
PopUpManager.addPopUp(titleWindow,this,false);
}

< fx:声明>
< modules:InspectorContainer />
< / fx:声明>




  1. 显示弹出窗口。弹出窗口是一个标题窗口,InspectorContainer(一个组)作为第一个元素。

  2. 在弹出的状态从默认状态改变到在线状态(这发生在用户点击一个按钮时)。在线状态有一个列表。该列表有一个itemrenderer。 itemrenderer有一个复选框。选中复选框。到目前为止这样好。 弹出(InspectorContainer)有一个mx:MenuBar实例。当您单击菜单栏中的某个项目时,菜单栏将显示一个菜单项。 点击菜单列表中的一个项目。 itemClick menuHandler被调用。在这个功能弹出状态改变。

这是错误发生的时间。

解决方案

下面是完整的代码:

 <?xml version =1.0encoding =utf-8?> 
xmlns:s =library://ns.adobe.com/flex/spark
xmlns:mx =library://ns.adobe.com/flex/mx
autoDrawBackground =true
width =100%
implements = mx.managers.IFocusManagerContainer>

< fx:Script>
<![CDATA [
public function get defaultButton():IFlexDisplayObject {
return null;


public function set defaultButton(value:IFlexDisplayObject):void {
// do not $ $ $ b}

override public function get systemManager():ISystemManager {
返回null;
}
]]>
< / fx:Script>

<! - 其他资料 - >


< / s:ItemRenderer>

解决方案是实现IFocusManagerContainer或基本上所需的功能。在我的情况下,我不得不重写Scroller focusInHandler处理程序中焦点事件的目标对象(组件)的容器中的systemManager getter。



我是这样想的。 Scroller focusInHandler发生错误。焦点事件(event.target)的目标属性是复选框(最后一个有焦点的项目)。复选框的容器是我的ItemRenderer。这是我实现IFocusManagerContainer接口的地方。我提到这一点,因为沿着这条路有5个或更多的父级。



在ItemRenderer中添加了:

  override public function get systemManager ():ISystemManager {
return null;

code $


这个方法是你实现mx.managers .IFocusManagerContainer接口。

该接口还要求我定义defaultButton getter和setter,但是没有必要解决这个错误。在测试中,我删除了接口,删除了defaultButton成员,并离开了systemManager getter,只是它仍然解决了这个问题。



另外,感谢noobsarepeople2的帮助。

In the Scroller.as class line 2139 I'm getting the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at spark.components::Scroller/focusInHandler()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\Scroller.as:2139]
    at flash.display::Stage/set focus()

From Scroller.as

/**
 *  @private 
 *  Listens for any focusIn events from descendants 
 */ 
override protected function focusInHandler(event:FocusEvent):void
{
    super.focusInHandler(event);

    // When we gain focus, make sure the focused element is visible
    if (viewport && ensureElementIsVisibleForSoftKeyboard)
    {
        var elt:IVisualElement = focusManager.getFocus() as IVisualElement; 
        lastFocusedElement = elt;
    }
}

Since this is framework code what option do I have to prevent it?

Context
I have created a pop up TitleWindow, added a Module in it and displayed it. The Module has a few States, in each State is a Group, one Group has a List, that List has an ItemRenderer, that ItemRenderer has a Checkbox.

The Module also has a Menu. When the Menu is opened the menu pop up lists the states the Module has available. When an item is selected from the menu pop up I change to another state.

When the state is changed and the last item is the checkbox then the error is generated. At least that's what I think is happening. I deduced this because in the Scroller class the handler is handling an event. On that event is the current target. That current target is the checkbox.

Update - Steps to reproduce

// inside the Application.mxml
// define variables
public var popup:Group;
public var titleWindow:TitleWindow;


// shows pop up
public function showInspector():void {

    // inside show inspector method
    // create new inspector container
    popup = new InspectorContainer(); // a group implements="mx.managers.IFocusManagerContainer"
    titleWindow = new TitleWindow();
    titleWindow.addElement(popup);

    // display pop up title window
    PopUpManager.addPopUp(titleWindow, this, false);
}

<fx:Declarations>
    <modules:InspectorContainer/>
</fx:Declarations>

  1. Show pop up. The pop up is a Title Window with InspectorContainer (a group) as the first element.

  2. In pop up change from home state (default state) to online state (this happens when the user clicks a button). The online state has a List. The List has an itemrenderer. The itemrenderer has a checkbox. Select the checkbox. So far so good.

  3. The pop up (InspectorContainer) has a mx:MenuBar instance. When you click on an item in the menubar the menubar displays a menu items.

  4. Click an item in the menu list. The itemClick menuHandler is called. In this function the pop up changes state.

This is when the error occurs.

解决方案

Here's the full code:

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
            xmlns:s="library://ns.adobe.com/flex/spark" 
            xmlns:mx="library://ns.adobe.com/flex/mx" 
            autoDrawBackground="true"
            width="100%"
            implements="mx.managers.IFocusManagerContainer">

    <fx:Script>
    <![CDATA[
        public function get defaultButton():IFlexDisplayObject {
            return null;
        }

        public function set defaultButton(value:IFlexDisplayObject):void {
            // do nothing
        }

        override public function get systemManager():ISystemManager {
            return null;
        }
    ]]>
    </fx:Script>

    <!-- other stuff -->

    <s:CheckBox id="enabledCheckbox" />

</s:ItemRenderer>

The solution was to implement the IFocusManagerContainer or basically the function it needed. In my case I had to override the systemManager getter in the container of the target object (component) of the focus event in the Scroller focusInHandler handler.

I figured it out this way. The error occurs in the Scroller focusInHandler. The target property of the focus event (event.target) is the Checkbox (the last item to have focus). The container of the Checkbox is my ItemRenderer. This is where I implemented the IFocusManagerContainer interface. I mention this because there are 5 or more parent levels along this path.

In the ItemRenderer I added:

override public function get systemManager():ISystemManager {
    return null;
}

This method is a method you have to implement when you implement the mx.managers.IFocusManagerContainer interface.

That interface also required me to define the defaultButton getter and setter but it was not necessary to solve this error. In tests I removed the interface, removed the defaultButton members and left the systemManager getter and with just that it still solved the problem.

Also, thanks to noobsarepeople2 for help.

这篇关于焦点管理器在Scroller类中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆