</pre><pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()"> <fx: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,111); } } 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全部初始化 ]]> </fx: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> </s:Application>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。