3 Replies Latest reply on Apr 14, 2009 9:46 AM by Miggl

    Setting Focus Problems

    Miggl Level 1

      When using focusManager.setFocus(txtfield) in a module, it appears to loose its focus.

       

      I'm not sure why this is happening, since I am setting focus after the module has been created. The following is the code for my module:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Module 
           xmlns:mx="http://www.adobe.com/2006/mxml" 
           layout="absolute"
           creationComplete="mdl_init()"
      >
           <mx:RemoteObject
                id="LoginRemote"
                destination="login"
                showBusyCursor="true"
           >
                 <mx:method name="sign_in" result="signin_handle(event)" />
                 <mx:method name="sign_out" result="signout_handle(event)" />
           </mx:RemoteObject>
           <mx:Script>
                <![CDATA[
                     import mx.rpc.events.FaultEvent;
                     import mx.utils.ArrayUtil;
                     import mx.rpc.events.ResultEvent;
                     import mx.controls.Alert;
                     import com.brassworks.ValueObjects.CurrentUserVO;
                     import mx.events.VideoEvent;
                     
                     [Bindable]
                     private var this_user:CurrentUserVO = new CurrentUserVO();
                     
                     private function mdl_init():void
                     {
                          focusManager.setFocus(txt_username);
                     }
                     
                     private function signin_handle(event:ResultEvent):void
                     {
                               this_user = event.result as CurrentUserVO;
                               if (this_user.token == null) {Alert.show("Supplied login credentials are not valid. Please try again.");}
                               else
                               {
                                    this.parentApplication.setUser(this.this_user);
                               }
                     }
      
                     private function signout_handle(event:ResultEvent):void
                     {
                          
                     }
                     
                     private function sign_in(event:Event):void
                     {
                          //Alert.show(txt_name.text + "|" + txt_password.text);
                          LoginRemote.sign_in(txt_username.text, txt_password.text);
                     }
      
                     private function sign_out(event:Event):void
                     {
                          
                     }
                     
                     private function show_error(error:Error, s_function:String):void
                     {
                          Alert.show("Method:" + s_function + "\nName: " + error.name + "\nID: " + error.errorID + "\nMessage: " + error.message + "\nStack Trace: " + error.getStackTrace() + "\nError: " + error.toString());
                     }
                     
                     private function handleFault(event:FaultEvent):void
                     {
                          Alert.show(event.fault.faultDetail, event.fault.faultString);
                     }
      
                ]]>
           </mx:Script>
           <mx:Panel
                id="pnl_signin"
                title="Sign In"
                horizontalAlign="center"
                verticalAlign="middle"
           >
                <mx:Form
                     id="frm_signin"
                     cornerRadius="5"
                     defaultButton="{btn_signin}"
                >
                     <mx:FormItem
                          id="fi_username"
                          label="Username:"
                     >
                          <mx:TextInput
                               id="txt_username"
                          />
                     </mx:FormItem>
                     <mx:FormItem
                          id="fi_password"
                          label="Password:"
                     >
                          <mx:TextInput
                               id="txt_password"
                               displayAsPassword="true"
                          />
                     </mx:FormItem>
                </mx:Form>
                <mx:ControlBar>
                     <mx:LinkButton
                          id="lnk_request_password"
                          label="Forgot your password?"
                          click="currentState='RequestPassword'"
                     />
                     <mx:Spacer
                          id="spc_spacer" 
                          width="100%"
                     />
                     <mx:Button
                          id="btn_signin"
                          label="Sign In"
                          click="sign_in(event)"
                     />
                </mx:ControlBar>
           </mx:Panel>
           <mx:states>
                <mx:State
                     name="RequestPassword"
                >
                     <mx:SetProperty
                          target="{pnl_signin}"
                          name="title"
                          value="Request New Password"
                     />
                     <mx:SetProperty
                          target="{btn_signin}"
                          name="label"
                          value="Submit Request"
                     />
                     <mx:RemoveChild
                          target="{lnk_request_password}"
                     />
                     <mx:RemoveChild
                          target="{fi_password}"
                     />
                     <mx:AddChild
                          relativeTo="{spc_spacer}"
                          position="before"
                     >
                          <mx:target>
                               <mx:LinkButton
                                    id="lnk_sign_in"
                                    label="Return to Sign In form."
                                    click="currentState=''"
                               />
                          </mx:target>
                     </mx:AddChild>
                </mx:State>
           </mx:states>
           
           <mx:transitions>
                <mx:Transition
                     fromState="*"
                     toState="*"
                >
                     <mx:Parallel
                          id="trn_default"
                          targets="{['RequestPassword']}"
                     >
                          <mx:Fade
                               alphaFrom="0.0"
                               alphaTo="1.0"
                          />
                     </mx:Parallel>
                </mx:Transition>
           </mx:transitions>
      </mx:Module>
      

       

      Ideas?

       

      Thanks!

      Mike