views:

28

answers:

1

I've wrote a custom itemrenderer for a List component (Flex 3.5) which is a VBox with a Label and a TextArea wrapped inside. All works fine so far but I want the TextArea in the first itemrenderer to receive focus so that it instantly becomes editable when tabbing onto the List. Is that possible and if how would I achieve this?

I've already added an event listener that selects the item at index 0 but the textArea in it should also be focussed at that moment ...

_list.addEventListener(FocusEvent.FOCUS_IN, onListFocusIn);

private function onListFocusIn(e:FocusEvent):void
{
 _list.selectedIndex = 0;
}
+1  A: 

There isn't much of an event for that. One hackery way to do it is to override updateDisplayList for your itemRenderer

<mx:Script>
    <![CDATA[
        import mx.controls.listClasses.ListBase;
        import mx.managers.FocusManager;

        override protected function updateDisplayList(unscaledWidth:Number, 
                                                      unscaledHeight:Number):void{
            super.updateDisplayList(unscaledWidth, unscaledHeight);

            if(ListBase(owner).isItemSelected(data)){
                focusManager.setFocus(mytext);
             }
        } 
    ]]>
</mx:Script>

More details on http://butterfliesandbugs.wordpress.com/2007/06/25/how-to-know-when-my-itemrenderer-is-selected/

And

http://cookbooks.adobe.com/post_How_to_know_when_an_ItemRenderer_is_selected-5322.html

Faheem
Thanks Faheem! That trick does the job nicely!
loungelizard