我在Flex 3中有一个视图,我使用选项卡导航器和选项卡导航器中的许多视图。我需要知道哪个视图被点击了,因为它是一个特定的视图然后我需要采取行动,即如果点击id为“secondTab”的视图然后做一些事情。
我已将其设置为通知,我的问题是我需要能够知道它是什么视图。调用tab.GetChildByName
或类似的方法似乎只能让我回到TabSkin
对象。
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
width="100%"
height="100%"
xmlns:local="*"
creationComplete="onCreationComplete(event)">
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.controls.Button;
protected function onCreationComplete(event:Event):void {
for(var i:int = 0; i < myTN.getChildren().length; i++) {
var tab:Button = myTN.getTabAt(i);
tab.addEventListener(FlexEvent.BUTTON_DOWN, tabClickHandler);
}
}
private function tabClickHandler(event:FlexEvent):void {
var tab:Button;
if(event.currentTarget is Button) {
tab = event.currentTarget as Button;
// how do I access the actual view hosted in a tab that was clicked?
}
}
]]>
</mx:Script>
<mx:TabNavigator id="myTN">
<local:ProductListView id="firstTab"
label="First Tab"
width="100%" height="100%" />
<local:ProductListView id="secondTab"
label="Second Tab"
width="100%" height="100%" />
</mx:TabNavigator>
</mx:VBox>
答案 0 :(得分:3)
TabNavigator
是ViewStack
的子类,当您选择标签时,它会触发change
事件。
<mx:TabNavigator id="myTN" change="childChanged()">
<local:ProductListView id="firstTab"
label="First Tab"
width="100%" height="100%" />
<local:ProductListView id="secondTab"
label="Second Tab"
width="100%" height="100%" />
</mx:TabNavigator>
它很简单:
private function childChanged():void
{
if(myTN.selectedChild == this.firstTab) //or myTN.selectedIndex == 0
{
trace("selected the first one");
}
else if(myTN.selectedChild == this.secondTab) //or myTN.selectedIndex == 0
{
trace("selected the second one");
}
}
答案 1 :(得分:0)
由于TabNavigator
是ViewStack
的扩展,您可以使用selectedChild
属性访问所选视图:
private function tabClickHandler(event:FlexEvent):void {
view = myTN.selectedChild;
// Do what you need to do with it here...
}
有关TabNavigator如何工作的更多信息,请查看文档:
http://livedocs.adobe.com/flex/3/html/help.html?content=navigators_4.html