0 Replies Latest reply on Sep 8, 2009 8:49 AM by rickcr

    Why do I need to declare "defaultButton" ? (In a component form part of view stack)

    rickcr Level 1

      After doing some research and some help from FlexGuy in another thread, I realize that I need to make sure I have custom components initialized before accessing parts of the component.  Just recently I was thrown for a long time when I tried to first click on a form field that was part of a component in my view stack, I'd get:


      TypeError: Error #1009: Cannot access a property or method of a null object reference.
          at mx.managers::FocusManager/focusInHandler()[C:\autobuild\galaga\frameworks\projects\framew ork\src\mx\managers\FocusManager.as:601]


      With the debugger it's occuring in the focusInHandler method of FocusManager.as: (apparently _defaultButton is null.)


      // restore the default button to be the original one
                      if (defButton && defButton != _defaultButton)
                          defButton.emphasized = false;
                          defButton = _defaultButton;
                         _defaultButton.emphasized = true;


      This prompted me, on a whim, to delcare a defaultButton:


      <mx:Form id="empForm" defaultButton="{submitButton}">


      which refers to my submit button:


      <mx:Button id="submitButton" click="submitEmployee()" label="{submitLabel}"/>

      My question, is why is this necessary? In some examples I don't see this declared at all, but I seem to need it? (I'm calling creationPolicy="all" to make sure my components are initialized but I still seem to have to this defaultButton declared?)