Pregunta

Soy un novato flexible. Necesito desactivar algunas de las pestañas en una barra de pestañas flexible especificada, por configuración. Tengo problemas para iterar sobre las pestañas en la barra de pestañas. Si utilizo el comando getChildAt (), no desactiva el botón de pestaña, sino el contenido de ese botón de pestaña, por lo que no es bueno.

Gracias y saludos, Mohit Ranka

¿Fue útil?

Solución

Al preguntar sobre el código, siempre publique un caso de prueba mínimo. getChildAt () funcionará, por lo que está pasando algo más con tu código.

<mx:Script>
    <![CDATA[
        import mx.events.ItemClickEvent;
        import mx.controls.tabBarClasses.Tab;
        private function clickTab(event:ItemClickEvent):void {
            var target:TabBar = event.currentTarget as TabBar;
            var currTab:Tab;
            var parity:int = event.index & 1;
            /* disable all tabs at indices w/ same parity as clicked tab;
               enable tabs of opposite parity.
             */
            for (var i=0; i<target.numChildren; ++i) {
               currTab = target.getChildAt(i) as Tab;
               currTab.enabled = (i&1)^parity;
            }
        }
    ]]>
</mx:Script>

<mx:TabBar id="someTabs" itemClick="clickTab(event)">
    <mx:dataProvider>
        <mx:String>Foo</mx:String>
        <mx:String>Bar</mx:String>
        <mx:String>Baz</mx:String>
        <mx:String>Bam</mx:String>
    </mx:dataProvider>
</mx:TabBar>

Otros consejos

¿Por qué no usar un enlace a su configuración?

algo como

   enabled="{yourConfiguration.lastResult.enabled}"

Para aquellos que quieren una respuesta de trabajo para Flex 4.5 (probablemente Flex 4 también). Finalmente encontré una solución. Se siente como un truco para mí, pero Adobe no responde la llamada y está funcionando para mí. Aquí hay un ejemplo simplificado.

<!-- component that has the the TabBar in it... -->

<fx:Script>
    <![CDATA[
//imports here

import mx.core.UIComponent;

//imports

private function setTabEnabled(index:int,enabled:Boolean):void{
    var theTab:UIComponent = theTabBar.dataGroup.getElementAt(index) as UIComponent;
    if(theTab){theTab.enabled = enabled;}
}
]]>
</fx:Script>

<s:TabBar id="theTabBar"
    dataProvider="{viewStack}"/>

<mx:ViewStack id="viewStack">
    <s:NavigatorContent label="0th Tab">
        <!-- ...Content -->
    </s:NavigatorContent>
    <s:NavigatorContent label="1st Tab">
        <!-- ...Content -->
    </s:NavigatorContent>
    <s:NavigatorContent label="2nd Tab">
        <!-- ...Content -->
    </s:NavigatorContent>
</mx:ViewStack>

<!-- rest of the component that has the the TabBar in it... -->

Luego, simplemente llama a setTabEnabled (theTabIndex, trueFalse) en un controlador de eventos relacionado con lo que decida por qué la pestaña está habilitada o no.

Yo debería extender TabBar para admitir esto, pero ya he pasado suficiente tiempo tratando de averiguarlo.

Codificación feliz = D

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top