Adobe Air: scroller throws error when changes focu

2020-04-11 03:47发布

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()
    at mx.core::UIComponent/setFocus()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:9905]
    at spark.components::RichEditableText/setFocus()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\RichEditableText.as:3126]
    at spark.components.supportClasses::SkinnableTextBase/setFocus()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\supportClasses\SkinnableTextBase.as:1874]
    at mx.managers::FocusManager/activateWindowHandler()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\FocusManager.as:740]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:13152]
    at spark.components::WindowedApplication/nativeWindow_activateHandler()[E:\dev\4.y\frameworks\projects\airspark\src\spark\components\WindowedApplication.as:2739]

In my Adobe Air program, I got the above error, whenever I use my app, and switch focus around between this app and other applications. (I've tried several times and this error is reproducible.)

What causes this problem and how to fix it?

EDIT: my program has a stackview, and one of the stackviews has a list. This error above will occur when the list has at least one object in.

4条回答
ゆ 、 Hurt°
2楼-- · 2020-04-11 04:16

I was having this issue, and it turns out that it was caused by some buttons I had as item renderers in my grid. These buttons would change the view to a different section, and apparently keep focus after pressed, causing all sorts of trouble. I set them to focusEnabled=false, and it solved the problem.

查看更多
手持菜刀,她持情操
3楼-- · 2020-04-11 04:17

I've got the same problem in one of my projects and looks like it's known bug of SDK. In my case I just wrote custom Scroller class where added focusManager != null check. Something like

package components
{
    import flash.events.FocusEvent;
    import spark.components.Scroller;
    public class MyScroller extends Scroller
    {
        public function MyScroller()
        {
            super();
        }

        override protected function focusInHandler(event:FocusEvent):void
        {
            if(focusManager != null) {
                super.focusInHandler(event);
            }
        }
    }
}

Best regrads, Roman

查看更多
SAY GOODBYE
4楼-- · 2020-04-11 04:17

I know this is old but here is a solution that works for me.

dataGrid.scroller.addEventListener(FocusEvent.FOCUS_IN, dataGridFocusInHandler, false, 1);

and

protected function dataGridFocusInHandler(event:FocusEvent):void {
    if(dataGrid.scroller.focusManager == null) {
        event.stopImmediatePropagation();
    }
}

could also been applied to a list I anticipate

Cheers Adz

查看更多
ゆ 、 Hurt°
5楼-- · 2020-04-11 04:35

I ran into the same issue, and the root cause was that PopUpManager/PopUpAnchor would not properly set the focusManager if the component being popped up does not implement the IFocusManagerContainer interface. After implementing such interface, the problem goes away.

查看更多
登录 后发表回答