<?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>
flex TabNavigator 切换之前给出提示
转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
FLEX实践—动态切换应用皮肤
在同一个Application中动态切换主题,这里采用的是动态引用不同的CSS文件。 具体步骤如下: 1)创建CSS文件 skyTheme.css /* CSS file */.backgrou
flex application css object string -
Flex的TabNavigator中tab触发的事件
ete="
xml 选项卡 ide 回调方法 -
flex做图片切换(播放)
flex做图片切换(播放)Java代码 <?xmlversion="1.0"encoding="utf-8"?> <mx:Applic
xml 图片切换 xml文件 5e i++