5 Replies Latest reply: Dec 16, 2011 12:23 AM by kimsyv2011 RSS

    Flex 4.5: null object reference error on focus handling

    Swiffmaz Community Member

      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\projects\spark\src\sp ark\components\Scroller.as:1273]
      at flash.display::Stage/set focus()
      at mx.core::UIComponent/setFocus()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UI Component.as:9895]
      at mx.managers::FocusManager/activateHandler()[E:\dev\4.5.1\frameworks\projects\framework\sr c\mx\managers\FocusManager.as:689]

       

      This is the code of the application:

       

      
      <?xml version="1.0" encoding="utf-8"?>
      <s:Application
           xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark"
           initialize="application1_initializeHandler(event);">
           <fx:Script>
                <![CDATA[
                     
                     protected function application1_initializeHandler(event:Event):void
                     {
                          addEventListener("myComboBoxChanged", testHandler);
                     }
                     
                     private function testHandler(e:Event):void
                     {
                          currentState = "MyState2";
                     }
                     
      
                ]]>
           </fx:Script>
           <s:states>
                <s:State name="MyState1"/>
                <s:State name="MyState2"/>
           </s:states>
           
           <s:List includeIn="MyState1">
                <s:dataProvider>
                     <s:ArrayList>
                          <fx:String>A</fx:String>
                          <fx:String>B</fx:String>
                          <fx:String>C</fx:String>
                     </s:ArrayList>
                </s:dataProvider>
                <s:itemRenderer>
                     <fx:Component>
                          <s:ItemRenderer>
                               <s:CheckBox label="CheckBox {data}" change="dispatchEvent(new Event('myComboBoxChanged', true));" />
                          </s:ItemRenderer>
                     </fx:Component>
                </s:itemRenderer>
           </s:List>
           
      </s:Application>