1 Reply Latest reply on Sep 21, 2012 1:39 PM by echoFlex

    FocusManager defButton is null in Flex4.1

    echoFlex

      I have a login dialog which contains username and password textinput and a login button. After type the content I want to press Enter to login. However, this is throwing error in Flex 4.1. Basically in FocusManager, defButton is null. It is highlighted below. Flex 3.5 doesn't have this issue. Is this a known flex bug? Can anyone tell me the root causes?

       

         privatefunction defaultButtonKeyHandler(event:KeyboardEvent):void

      {       

              var sm:ISystemManager = form.systemManager;

              if (hasEventListener("defaultButtonKeyHandler"))

      if (!dispatchEvent(new FocusEvent("defaultButtonKeyHandler", false, true)))

      return;

       

              if (defaultButtonEnabled && event.keyCode == Keyboard.ENTER &&

      defaultButton && defButton.enabled)

              {

      sendDefaultButtonEvent();

          }

       

       

      Exception:


      TypeError: Error #1009: Cannot access a property or method of a null object reference.

                at mx.managers::FocusManager/defaultButtonKeyHandler()

                at flash.events::EventDispatcher/dispatchEventFunction()

                at flash.events::EventDispatcher/dispatchEvent()

                at mx.managers::SystemManager/keyDownHandler()[E:\dev\4.x\frameworks\projects\framework\src\ mx\managers\SystemManager.as:2675]

        • 1. Re: FocusManager defButton is null in Flex4.1
          echoFlex Level 1

          I did few tests today, found this is a Flex 4.1 issue. I am using Form. When set defaultButton in a Form, it throws exception sometimes when press enter. I pasted the sample code below.

          I also found a workaround, setting form defaultButton in creationComplete handler instead of on the mxml tag. I wonder if this is a timing issue?

          Any ideas?

           

          <?xml version="1.0" encoding="utf-8"?>

          <mx:Canvas xmlns:fx="http://ns.adobe.com/mxml/2009"

                                 xmlns:s="library://ns.adobe.com/flex/spark"

                                 xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%">

           

                    <fx:Script>

                              <![CDATA[

                                        import mx.controls.Alert;

                                        import mx.events.FlexEvent;

                                        protected function loginBtn_clickHandler(event:MouseEvent):void

                                        {

                                                  Alert.show(event.type.toString());

                                        }

                              ]]>

                    </fx:Script>

           

                    <mx:Form id="loginForm" defaultButton="{loginBtn}">

                              <mx:FormHeading width="100%" label="FlexForm"/>

                              <mx:FormItem id="nameLbl" label="Username">

                                        <mx:TextInput id="nameIpt" width="100" height="23"/>

                              </mx:FormItem>

                              <mx:FormItem id="pwdLbl" label="Password">

                                        <mx:TextInput id="pwdIpt" width="100" height="23"/>

                              </mx:FormItem>

                              <mx:FormItem id="btnForm">

                                        <mx:Button id="loginBtn" label="login" enabled="false" click="loginBtn_clickHandler(event)"/>

                              </mx:FormItem>

                    </mx:Form>

           

          </mx:Canvas>