2013-05-01 159 views
0

我有一個帶三個選項卡的TabbedViewNavigatorApplication。TabBar當前按鈕點擊

我想在再次單擊當前活動按鈕選項卡時調用一個函數。

怎麼辦?

回答

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> 
+0

非常感謝你。像魅力一樣工作! – goo 2013-05-02 03:38:09