开发者

Setting Focus on a List ItemRenderer with TextArea inside?

开发者 https://www.devze.com 2023-01-22 08:11 出处:网络
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 firs

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;
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号