Skip navigation
Currently Being Moderated

Flex 4.5: null object reference error on focus handling

Jul 21, 2011 6:01 AM

The spark list in the following listing is only included in MyState1. If a CheckBox is checked, the MyState2 is set and therefore the spark list is removed from stage.


If I run the application with debugger attached and i check a CheckBox and then focus out and focus in the browser's window there is an error:


TypeError: Error #1009: Cannot access a property or method of a null object reference
at spark.components::Scroller/focusInHandler()[E:\dev\4.5.1\frameworks\p rojects\spark\src\spark\components\]
at flash.display::Stage/set focus()
at mx.core::UIComponent/setFocus()[E:\dev\4.5.1\frameworks\projects\fram ework\src\mx\core\]
at mx.managers::FocusManager/activateHandler()[E:\dev\4.5.1\frameworks\p rojects\framework\src\mx\managers\]


This is the code of the application:


<?xml version="1.0" encoding="utf-8"?>
               protected function application1_initializeHandler(event:Event):void
                    addEventListener("myComboBoxChanged", testHandler);
               private function testHandler(e:Event):void
                    currentState = "MyState2";

          <s:State name="MyState1"/>
          <s:State name="MyState2"/>
     <s:List includeIn="MyState1">
                         <s:CheckBox label="CheckBox {data}" change="dispatchEvent(new Event('myComboBoxChanged', true));" />

  • Currently Being Moderated
    Jul 21, 2011 6:14 AM   in reply to Swiffmaz

    What's the code on the line where the debugger stops in the focusInHandler?

    Mark as:
  • Currently Being Moderated
    Jul 21, 2011 9:47 AM   in reply to Swiffmaz

    Focusable renderers aren't officially supported by Spark List.  I would make

    sure focus moves to some other thing when the List goes away.

    Mark as:
  • Currently Being Moderated
    Jul 21, 2011 9:58 AM   in reply to Flex harUI

    Yes, there are all kinds of problems when you remove something from the screen that had focus (for instance, at that point you can't capture keyboard events either).


    My code is sprinkled with so many things to make sure something is in focus, I tend to forget that I've done it.


    In your code that changes the currentState, add







    Mark as:
  • Currently Being Moderated
    Dec 16, 2011 12:23 AM   in reply to Swiffmaz

    Another way to do is to do a focusManager.deactivate(); on all controls that can have focus before removing them from stage.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points