2

I have a few TextAreas in a Flash CS5 form, and I want to remove the focus from the last selected TextArea if the user clicks elsewhere on the form. How can I do this?

Anonymous1
  • 3,877
  • 3
  • 28
  • 42

2 Answers2

2

assuming your stage is your form:

function setEventListeners():void
    {
    stage.addEventListener(MouseEvent.CLICK, mouseUpEventHandler);
    }

function mouseUpEventHandler(evt:MouseEvent):void
    {
    if  (!evt.bubbles)
        stage.focus = null;
    }

otherwise, add the event listener to your form object that has the textFields as its children instead of the stage.

Chunky Chunk
  • 16,553
  • 15
  • 84
  • 162
0

You would need some form of identifier to know when the last TextField has been clicked. This will allow you to set up a conditional.

The example I'm giving here is not only dealing with focus , it's also resetting the tabIndex of your fields, this can be handy in case a submission has been canceled & you don't want the focus on the middle of the form if the user is using TAB to navigate between the fields.

     //This Vector will hold your TextFields
     private var fields:Vector.<TextField>;
     private var fieldsDisabled:Boolean;

     private function clickHandler( event:MouseEvent ):void
     {
         if( event.currentTarget.name == "Last" )
         {
             enableTabs( false );
             fieldsDisabled == true;

         } else if ( fieldsDisabled )
         {
             enableTabs( true );
             fieldsDisabled == false;
         }
     }

     private function enableTabs( enabled:Boolean ):void
     {
         //provided the fields Vector has been populated...
         for( var i:int ; i < fields.length ; ++i )
              fields[i].tabEnabled = enabled;
     }
PatrickS
  • 9,539
  • 2
  • 27
  • 31