从子元素访问选项卡导航器及其子项

时间:2013-03-27 13:52:51

标签: actionscript-3 flex air flex4

我的主应用程序mxml我正在使用选项卡导航器,我可以通过以下代码访问应用程序中任何位置的选项卡导航器。

mx.core.FlexGlobals.topLevelApplication.menuOption.selectedIndex = 0;

现在我的问题是我在transactionUI中使用了一个切换按钮栏,它是tab导航器的子元素,如何像上面提到的代码一样访问该元素?

我的主要mxml标签导航器::

<mx:TabNavigator   left="10" top="20" bottom="10" right="10" id="menuOption" >

    <ui1:homeUI label="Home" width="100%" height="100%" backgroundColor="#373737" chromeColor="#181818" contentBackgroundColor="#181818" color="#FDFDFD" /> 

    <ui1:transactionUI label="Transaction" width="100%" height="100%" backgroundColor="#373737"  />     

        <ui1:calanderUI label="Employee service" width="100%" height="100%"  horizontalCenter="0"  backgroundColor="#373737" chromeColor="#181818" contentBackgroundColor="#181818" color="#FDFDFD" />
        <ui1:ManagementUI label="Management" width="100%" height="100%" backgroundColor="#373737" chromeColor="#181818" contentBackgroundColor="#181818" color="#FDFDFD" />
        <ui1:reportUI label="Reports" width="100%" height="100%" backgroundColor="#373737" chromeColor="#181818" contentBackgroundColor="#181818" color="#FDFDFD" />

        <ui1:admin label="Admin" width="100%" height="100%" backgroundColor="#373737" chromeColor="#181818" contentBackgroundColor="#181818" color="#FDFDFD" />

    </mx:TabNavigator>

在我的主应用程序mxml中我正在使用选项卡导航器,我可以通过以下代码访问应用程序中任何位置的选项卡导航器。

mx.core.FlexGlobals.topLevelApplication.menuOption.selectedIndex = 0;

现在我的问题是我在transactionUI中使用了一个切换按钮栏,它是tab导航器的子元素,如何像上面提到的代码一样访问该元素?

我的主要mxml标签导航器::

<ui1:homeUI label="Home" width="100%" height="100%" backgroundColor="#373737" chromeColor="#181818" contentBackgroundColor="#181818" color="#FDFDFD" /> 

<ui1:transactionUI label="Transaction" width="100%" height="100%" backgroundColor="#373737"  />     

    <ui1:calanderUI label="Employee service" width="100%" height="100%"  horizontalCenter="0"  backgroundColor="#373737" chromeColor="#181818" contentBackgroundColor="#181818" color="#FDFDFD" />
    <ui1:ManagementUI label="Management" width="100%" height="100%" backgroundColor="#373737" chromeColor="#181818" contentBackgroundColor="#181818" color="#FDFDFD" />
    <ui1:reportUI label="Reports" width="100%" height="100%" backgroundColor="#373737" chromeColor="#181818" contentBackgroundColor="#181818" color="#FDFDFD" />

    <ui1:admin label="Admin" width="100%" height="100%" backgroundColor="#373737" chromeColor="#181818" contentBackgroundColor="#181818" color="#FDFDFD" />

</mx:TabNavigator>

* 我在TransactionUI内的切换栏:: *

<s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%"
                xmlns:ui="com.colan.*" xmlns:ui1="com.colan.ui.*"
                backgroundColor="#373737" chromeColor="#181818" 
                contentBackgroundColor="#181818" color="#FDFDFD">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
    <![CDATA[

        import mx.collections.*;
        import mx.core.*;
    ]]>
</fx:Script>
<mx:VBox horizontalAlign="center"  verticalAlign="middle" width="100%"  height="100%">

    <mx:HBox horizontalAlign="center"  verticalAlign="middle" width="100%"  height="15%" >

        <mx:ToggleButtonBar id="toggleButtonBar"
                            dataProvider="{viewStack}"    
                            selectedButtonTextStyleName="mySelectedButtonTextStyleName"
                            />


    </mx:HBox>
    <mx:HBox horizontalAlign="center"  verticalAlign="middle" width="100%"  height="85%" >


        <mx:ViewStack id="viewStack"                 
                      visible="{toggleButtonBar.selectedIndex > -1}" width="100%"  height="100%" >

            <ui1:transaction label="Transaction"/>
            <ui1:addClient label="Add  Client"/>
            <ui1:invoice label="Make invoice"/>
            <ui1:workCatalogue label="Work catalogue"/>
            <ui1:productCataloge label="Products Categories"/>

            <ui1:suppliers label="Offers"/>
            <ui1:calendarPlanUI label="Calendar"/>


        </mx:ViewStack>
    </mx:HBox>
</mx:VBox>

请建议我......

1 个答案:

答案 0 :(得分:0)

((mx.core.FlexGlobals.topLevelApplication.menuOption).getChildAt(1)as transactionUI).toggleButtonBar

虽然这很粗糙,但可以帮助你开始。尚未测试过。