Access a view inside a tab navigator when a tab is clicked

Posted by magnus.lassi on Stack Overflow See other posts from Stack Overflow or by magnus.lassi
Published on 2010-05-19T13:43:32Z Indexed on 2010/05/19 14:10 UTC
Read the original article Hit count: 344

Filed under:
|

Hi, I I have a view in Flex 3 where I use a tab navigator and a number of views inside the tab navigator. I need to be know which view was clicked because of it's one specific view then I need to take action, i.e. if view with id "secondTab" is clicked then do something.

I have set it up to be notified, my problem is that I need to be able to know what view it is. Calling tab.GetChildByName or a similar method seems to only get me back a TabSkin object.

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" 
width="100%" 
height="100%"   
xmlns:local="*"
creationComplete="onCreationComplete(event)">

<mx:Script>
    <![CDATA[
        import mx.events.FlexEvent;
        import mx.controls.Button;

        protected function onCreationComplete(event:Event):void  {
            for(var i:int = 0; i < myTN.getChildren().length; i++) {
                var tab:Button = myTN.getTabAt(i);
                tab.addEventListener(FlexEvent.BUTTON_DOWN, tabClickHandler);
            }               
        }

        private function tabClickHandler(event:FlexEvent):void {
            var tab:Button;

             if(event.currentTarget is Button) {
                tab = event.currentTarget as Button;

                // how do I access the actual view hosted in a tab that was clicked?
             }
        }



    ]]>
</mx:Script>

<mx:TabNavigator id="myTN">
    <local:ProductListView id="firstTab" 
                            label="First Tab" 
                            width="100%" height="100%" />
    <local:ProductListView id="secondTab" 
                            label="Second Tab" 
                            width="100%" height="100%" />
</mx:TabNavigator>


</mx:VBox>

© Stack Overflow or respective owner

Related posts about flex

Related posts about flex3