flex TabNavigator 切换之前给出提示(转)

<?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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值