2010-12-23 64 views
0

我有一个viewstack容器,有3个视图:红色,黑色和蓝色。我怎么能完全隐藏黑色&不包括它呢?隐藏viewstack容器的容器

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"  
      xmlns:mx="library://ns.adobe.com/flex/mx"  
      xmlns:s="library://ns.adobe.com/flex/spark" 
      horizontalCenter="0" verticalCenter="0" 
      > 

<mx:LinkBar dataProvider="{myVS}" borderVisible="false" color="blue" disabledColor="black" /> 

<mx:ViewStack id="myVS" borderVisible="false" width="100%" height="100%" > 

    <mx:VBox id="red" label="click red" horizontalAlign="center" verticalAlign="middle" > 
     <s:Label id="r1" color="red" fontSize="25" text="This is the red label" /> 
    </mx:VBox> 

    <mx:VBox id="black" label="click black" horizontalAlign="center" verticalAlign="middle" > 
     <s:Label id="r2" color="black" fontSize="25" text="This is the black label" /> 
    </mx:VBox> 

    <mx:VBox id="blue" label="click blue" horizontalAlign="center" verticalAlign="middle" > 
     <s:Label id="r3" color="blue" fontSize="25" text="This is the blue label" /> 
    </mx:VBox> 

</mx:ViewStack> 

</s:Application> 

回答

1

我担心我可能会错过您的问题的意图。 ViewStack组件用于显示多个视图“堆叠”在一起,只有视图一次显示。它不包含像TabNavigator可能的内置导航。如果你想“完全隐藏”黑色视图,只需在编译代码之前将其注释掉,因此它永远不会显示。

我你的代码示例,您使用的是与则ViewStack作为数据提供程序的链接吧中看到的,所以也许你的意思是问如何保持黑色的观点出来ØLinkBar中。只是执行一些神奇的ActionScript创建自定义数据提供程序:

var dataProvider : ArrayCollection = new ArrayCollection([ 
{label:"click Red"}, 
{label:"click blue"} 
]); 

,并指定数据提供程序作为数据提供程序源为您linkBar:

<mx:LinkBar dataProvider="{dataProvider}" borderVisible="false" color="blue" disabledColor="black" /> 
0

我认为快速和肮脏的方法是只是将其删除:

myVS.removeElement(black); 

不过,我想我会使用视图状态来代替。这可以让你稍后再回来,而无需弄清楚如何/在哪里放回去。定义你的状态:

<s:states> 
    <s:State name="all" /> 
    <s:State name="notBlack" /> 
</s:states> 

而在你的“黑” VBox,从“notBlack”状态排除:

<mx:VBox id="black" excludeFrom="notBlack" ... /> 

然后,当你想删除它,你可以通过设置这样做currentState

<s:Button click="currentState='notBlack'" label="remove black" /> 
+0

使用状态和ViewStacks在一起吗?这是疯狂的。我不明白为什么它不会工作,但他们有时被作为两种不同的方法,以同样的目的。 – JeffryHouser 2010-12-23 03:39:56