我是一个灵活的新手。我需要通过配置禁用指定的flex tabbar中的某些选项卡。我在迭代选项卡栏中的选项卡时遇到了麻烦。如果我使用getChildAt()命令,它不会禁用选项卡按钮,而是禁用该选项卡按钮的内容,所以它没有用。

谢谢和问候, Mohit Ranka

有帮助吗?

解决方案

在询问代码时,请始终发布最小的测试用例。 getChildAt()将起作用,因此您的代码还会发生其他事情。

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

其他提示

为什么不使用可绑定的配置?

类似

   enabled="{yourConfiguration.lastResult.enabled}"

对于那些想要获得Flex 4.5工作答案的人(也可能是Flex 4)。我终于找到了解决方案。这对我来说感觉像是一个黑客,但Adobe没有接听电话,而且它对我有用。这是一个简化的例子。

<!-- 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... -->

然后你只需在事件处理程序中调用 setTabEnabled(theTabIndex,trueFalse),该事件处理程序与决定选项卡启用或不启用的原因有关。

扩展TabBar以支持此功能,但我已经花了足够的时间试图解决这个问题。

快乐编码= D

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top