我有一个带有三个标签的选项卡式视图导航器应用程序。
我想在再次点击当前活动按钮标签时调用一个函数。
怎么做?
答案 0 :(得分:2)
以下是解决此任务的几种方法,请参阅以下内容:
<?xml version="1.0" encoding="utf-8"?>
<s:TabbedViewNavigatorApplication
xmlns:fx="http://ns.adobe.com/mxml/2009"
creationComplete="handler_creationCompleteHandler(event)"
xmlns:s="library://ns.adobe.com/flex/spark" applicationDPI="160">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import spark.components.ButtonBarButton;
protected function handler_creationCompleteHandler(event:FlexEvent):void
{
var lastTabbedButtonIdex:uint = this.tabbedNavigator.tabBar.selectedIndex;
this.tabbedNavigator.tabBar.addEventListener(MouseEvent.CLICK, handler_onTabBarClick);
function handler_onTabBarClick(event:MouseEvent):void
{
if(lastTabbedButtonIdex == (event.target as ButtonBarButton).itemIndex)
{
trace("Click on selected button");
}
else
{
trace("Select other button");
}
lastTabbedButtonIdex = (event.target as ButtonBarButton).itemIndex;
}
this.removeEventListener(FlexEvent.CREATION_COMPLETE, handler_creationCompleteHandler);
}
]]>
</fx:Script>
<s:ViewNavigator label="About" width="100%" height="100%" firstView="views.AboutView"/>
<s:ViewNavigator label="Test" width="100%" height="100%" firstView="views.TestView"/>
<s:ViewNavigator label="Feed" width="100%" height="100%" firstView="views.FeedView"/>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:TabbedViewNavigatorApplication>