2

I have a main application calling several ViewStack states, each with popup windows. If I don't open any popup windows, I can move between states fine. If I open a popup window then try to change the state using currentState=... I get the 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()
at mx.core::UIComponent/setFocus() [E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:9905]
...

I see others having the same problem, for example here:

http://forums.adobe.com/thread/1031531

http://forums.adobe.com/message/2767130

http://forums.adobe.com/message/3448443

http://forums.adobe.com/thread/655749?tstart=-1

http://forums.adobe.com/thread/801149

http://flex4examples.wordpress.com/2011/05/05/skinnabletextbase-focusmanager-runtime-error-popup/

http://bugs.adobe.com/jira/browse/SDK-32036?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel

But I haven't figured out how to implement the recommended solution. It sounds like I should just include:

import mx.managers.PopUpManager; PopUpManager;

inside my main application and it should work, but it doesn't work for me.

My application has each view state in a different file, each defined using <views:View>. Also, all of the popups are separate files defined as <s:TitleWindow>. Each file includes this line:

import mx.managers.PopUpManager;

I wonder if this means each file is using a different popup manager(?), when it's a singleton and only one should be used for the whole app (how to set that up?).

The code I use to call a popup is:

var _popupName:MyTitleWindowFileName = MyTitleWindowFileName(
    PopUpManager.createPopUp(this, MyTitleWindowFileName, true));   
_popupName.addEventListener(MyAppController.CLOSE_POPUP,onClosePopUp); 
PopUpManager.centerPopUp(_popupName); // call popup 

Note that when the main application (the one defined as <s:Application>) runs, the ViewStack states have not been loaded yet (since they get loaded when they are used the first time). Not sure if that has any cause/effect here.

I've tried to follow Adobe's example code in the "Passing data to and from a Spark pop-up window" section here:

http://help.adobe.com/en_US/flex/using/WS6c678f7b363d5da52e8f1ca1124a0430dcf-8000.html#WS6c678f7b363d5da52e8f1ca1124a0430dcf-7ffe

Any ideas much appreciated.

ggkmath
  • 4,188
  • 23
  • 72
  • 129
  • 1
    Your error is different from all the other ones in the forum posts. Also the comment about putting a reference `PopUpManager` in the main application only applies if you are using Flex modules. In this case, when you change states the scroll bars are receiving focus, and causing the error. Question: which view are you changing the state in (main app, view stack child view, or pop up) when this happens? – Sunil D. Jul 08 '12 at 18:56
  • I'm changing the state in the view stack child view. If I open a popup then change the state, and remove the popup window, the error occurs. However, if I open a popup, then select something that takes the focus away from the popup, like manually clicking a spark DropDownList or TextInput in the view stack child view, then change the state and remove the popup, the error does not occur. – ggkmath Jul 08 '12 at 20:05
  • @ggkmath - Were you able to solve this? This is the exact same scenario I am in. Open a pop up, changes state and then the error. – 1.21 gigawatts Jul 17 '12 at 20:17
  • @ggkmath - I was able to solve this using the solution here http://stackoverflow.com/questions/11516121/focus-manager-bug-in-scroller-class/11813474#11813474 – 1.21 gigawatts Aug 05 '12 at 02:22

2 Answers2

1

Based on your comments, it seems like the error occurs because the focus remains in the popup. I would expect the PopUpManager and FocusManager classes to handle this better.

One thing I can think of is that the FocusManager may be trying to handle this. But since the state changes, the item that originally had focus (in the view stack child, before the pop up was opened) may no longer be there when the view state changes. Just a hunch, w/out seeing your code.

Here's some things you can do to either work around the problem (or better) further debug it to understand what is happening:

  • Use FocusManager.setFocus() to move the focus back to an object in the view stack child before closing the pop up

  • Use FocusManager.getFocus() to debug and see where it thinks the focus is at various stages (before opening popup, before/after changing state, and before/after closing pop up).

Sunil D.
  • 17,983
  • 6
  • 53
  • 65
  • Thanks Sunil, I've been trying to play around with setFocus() this morning. The idea is to programmatically "click" a feature in the view stack child, as if the user had manually clicked it. Before leaving the view stack, if I execute `myTextInputId.setFocus();` then the error goes away. However, executing `focusManager.setFocus(myButtonId);` instead, does not work. Nor does executing `myLabelId.setFocus();`. As not all of my view stack childs have a TextInput component, not sure if this is an acceptable solution. I'd love to know what's going on. – ggkmath Jul 08 '12 at 20:35
  • Note, there can be multiple FocusManager's in your app. Each one manages it's own "tab loop". For example, a popup has it's own FocusManager b/c when the user presses the "tab" key it will only move the focus w/in the pop up. When you do `focusManager.setFocus(myButtonId)` is this the `FocusManager` from the child view or the pop up? – Sunil D. Jul 08 '12 at 20:47
  • The only time I've ever used the FocusManager is in that one line of code. Since it is located in the view stack child view (not the pop up), I'd guess it is the FocusManager for the view stack child. – ggkmath Jul 08 '12 at 20:51
  • Hmm, you may want to post your code or a simple example of what is going on. Sounds like you need to step through the code in the debugger to see why it is failing. – Sunil D. Jul 08 '12 at 20:52
0

It appears this is the situation I'm experiencing:

Adobe Air: scroller throws error when changes focus between different applications

It's an Adobe bug. Solution from Adobe is:

This bug is easily fixed by changing Scroller to do a null pointer check on focusManager before using it.

which is what the first link above attempts to do.

Another link: http://forums.adobe.com/message/3812805

Community
  • 1
  • 1
ggkmath
  • 4,188
  • 23
  • 72
  • 129