flex TabNavigator 切換之前給出提示

來源:互聯網
上載者:User

下面代碼是我做的例子:

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
  creationComplete="init()">
<mx:Script>
 <![CDATA[
  import mx.controls.TabBar;
  import mx.controls.Button;
  import mx.controls.Alert;
  import mx.events.CloseEvent;
  import mx.managers.PopUpManager;
  
  private var iTabIndex:int;
  private var iToTabIndex:int;
  private var _updateAlert:Alert;
  
  public function init():void
  {
   iTabIndex = 0;
   iToTabIndex = 0;
   var btn:Button;
   for(var i:int=0;i<tab.getChildren().length;i++)
   {
    btn = tab.getTabAt(i);
    btn.addEventListener(MouseEvent.MOUSE_DOWN,tabClickHandler,false,999999999);
   }
  }
  private function tabClickHandler(event:MouseEvent):void
     {
         iToTabIndex = event.currentTarget.parent.getChildIndex(event.currentTarget);
         //終止事件
         event.stopImmediatePropagation();
         //給出提示message
         if(iToTabIndex !=iTabIndex)
         {
          showGoBack();
         }
     }
     // alert
  public function showGoBack():void
  {
   Alert.buttonWidth = 100;
   Alert.yesLabel    = "yes";
   Alert.noLabel     = "no";
   var updateLabel:String =  "要切換tab嗎?";

   this._updateAlert = Alert.show(updateLabel, "", Alert.YES | Alert.NO);
   this._updateAlert.addEventListener(CloseEvent.CLOSE,closeShowGoBack); 
  }
  private function closeShowGoBack(e:CloseEvent):void
  {
   switch (e.detail)
   {
    case Alert.YES:            
     iTabIndex    = iToTabIndex;
     tab.selectedIndex   = iTabIndex;
     break;
    case Alert.NO:
     PopUpManager.removePopUp(this._updateAlert);
     break;
   }   
  }
  
  public function change(e:Event):void
  {
   Alert.show("CHANGE " + tab.selectedIndex.toString() + "!!!");
   
  }
  //注釋;creationPolicy="all",把tab的所有child全部初始化
  
  
 ]]>
</mx:Script>
 <mx:TabNavigator creationPolicy="all" id="tab" x="21" y="28" change="change(event)" width="200" height="200" >
  <mx:Canvas id="a" label="aa" width="100%" height="100%">
   <mx:TextInput x="10" y="10" width="178"/>
  </mx:Canvas>
  <mx:Canvas id="b" label="bb" width="100%" height="100%">
   <mx:Button id="abtn" x="10" y="50" label="Button"/>
  </mx:Canvas>
 </mx:TabNavigator>
</mx:Application>

 

注意:本代碼是本人發了多半天的時間,查文檔,解決的。如果有人引用,請註明地址,謝謝!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.