2012-12-10 66 views
1

在我的主应用程序MXML我使用一个标签导航标签导航,我可以用下面的代码在任何地方访问该选项卡浏览器在应用..访问的子元素

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

现在我的问题是我IHAVE使用切换按钮栏transactionUI这是一个标签导航器的子元素,我如何访问像上面提到的代码那样的元素?

我的主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> 

内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

你们是不是全局访问的标签导航的孩子或你想从孩子访问的标签导航?你的头衔说了一件事,但你的帖子说另一件事。再说一句建议,如果你用全局变量来处理所有事情,你的代码将非常快速地变得非常难以管理。您真的应该考虑为应用程序的不同部分添加某种数据模型或框架以进行通信。 – Osman

+1

你不应该。查看MVC框架并选择一个。试图访问另一个视图最终会导致以后休息。 OOP试图用像MVC这样的设计模式来防止这种情况。 –

回答

1

F lexGlobals.topLevelApplication旨在从任何子屏幕访问主应用程序屏幕中的公共变量/函数。

例如.. 如果“transactionUI”NavigatorContent的ToggleButtonBar“calendarPlanUI”用于迁移到主应用程序“calanderUI”NavigatorContent。 然后你就可以马上提到它,然后有喜欢

<ui1:calendarPlanUI label="Calendar" click="mx.core.FlexGlobals.topLevelApplication.menuOption.selectedIndex = '2'"/> 

但是,如果你想为toggleButtonBar这样

mx.core.FlexGlobals.topLevelApplication.toggleButtonBar.selectedIndex = 1; 

话,我想提一提任何机会,主要的应用程序中的变量/功能/组件只能使用“topLevelApplication”访问。在没有创建实例到transactionUI的情况下,您将无法在其他子屏幕/主应用程序中使用toggleButtonBar。