3 Replies Latest reply on Dec 14, 2007 12:23 PM by jkj14

    Set focus to textfield

    kingdom_of_revenge
      Hi guyz I knew this is a simple problem.Im just a beginner someone please help me.
      Im creating the text field at runtime.By default i just want to set the focus to the textfield

      karan
        • 1. Re: Set focus to textfield
          rvollmar Level 1
          Hello,
          Try using setFocus(). Here's an example.
          - Rob

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="doCreationComplete()" >
          <mx:Script>
          <![CDATA[
          import mx.controls.TextArea;

          private function doCreationComplete():void{
          var ta2:TextArea = new TextArea();
          ta2.text = "I should have focus.";
          hbx2.addChild(ta2);
          ta2.setFocus();
          }
          ]]>
          </mx:Script>

          <mx:HBox id="hbx1">
          <mx:Label text="ta1:" />
          <mx:TextArea id="ta1" />
          </mx:HBox>

          <mx:HBox id="hbx2">
          <mx:Label text="ta2:" />
          </mx:HBox>
          </mx:Application>
          • 2. Re: Set focus to textfield
            ntsiii Level 3
            Be aware that when you first load a Flex app, the Flash Player itself does not have the focus. Therefore, your control will have the focus within the app, but you will not be able to start typing directly.

            Tthe usual fixfor this is to have a piece of javascript in the html wrapper that sets the focus to the Flash Player.

            Tracy
            • 3. Re: Set focus to textfield
              jkj14

              how exactly can this be done using the index.template.html in flex builder 2 project?(a working sample would be nice)