首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

打包自己的Flex工具_MyTabNavigator

2012-11-23 
封装自己的Flex工具_MyTabNavigatorflex的组件中有TabNavigator,在日常的情况下基本可以满足工程的要求了,

封装自己的Flex工具_MyTabNavigator
flex的组件中有TabNavigator,在日常的情况下基本可以满足工程的要求了,但如果想扩展一下,增强一下功

能呢?
这个TabNavigator就显得很原始了,所以有必要扩展一下它的功能了!
这次的目的:让TabNavigator可以双击放大,缩小!
1.集成自TabNavigator

public class MyTabNavigator extends TabNavigator{}

2.覆盖TabNavigator的createChildren().以完成独有的功能
override protected function createChildren():void{super.createChildren();tabBar.doubleClickEnabled=true;tabBar.addEventListener(MouseEvent.DOUBLE_CLICK,doubleClickHandler);tabBar.addEventListener(Event.REMOVED_FROM_STAGE,clean);}

3.完成双击的事件
//双击处理
private function doubleClickHandler(e:MouseEvent):void{if(!done){//保存状态pos.x = x;pos.y = y;pos.width = width;pos.height = height;pos.percentWidth = percentWidth;pos.percentHeight = percentHeight;oldParent = parent;oldIndex = parent.getChildIndex(this);//放大tabwidth = stage.width;height = stage.height;Application.application.addChild(this); //这里直接加入到application,不必加入到stage了x = 0;y = 0;done=true;}else{//还原x = pos.x;y = pos.y;if(pos.percentWidth)percentWidth = 100;elsewidth = pos.width;if(pos.percentHeight)percentHeight = 100;elseheight = pos.height;oldParent.addChildAt(this,oldIndex);done=false;}}

4.以下是 全部的code
====================================================
package org.sk.controls{import flash.display.DisplayObject;import flash.display.DisplayObjectContainer;import flash.events.Event;import flash.events.MouseEvent;import mx.containers.TabNavigator;import mx.core.Application;/*** 新的 TabNavigator,双击可以放大缩小* */public class MyTabNavigator extends TabNavigator{private var pos:Object={};//原位置信息private var oldParent:DisplayObjectContainer; //原容器private var oldIndex:uint; //原位置private var done:Boolean=false; //变化标识public function MyTabNavigator(){super();}//覆盖override protected function createChildren():void{super.createChildren();tabBar.doubleClickEnabled=true;tabBar.addEventListener(MouseEvent.DOUBLE_CLICK,doubleClickHandler);tabBar.addEventListener(Event.REMOVED_FROM_STAGE,clean);}private function clean(e:Event):void{tabBar.removeEventListener(Event.REMOVED_FROM_STAGE,clean);}//双击处理private function doubleClickHandler(e:MouseEvent):void{if(!done){ //加入到根舞台,保存状态,并放大pos.x = x;pos.y = y;pos.width = width;pos.height = height;pos.percentWidth = percentWidth;pos.percentHeight = percentHeight;oldParent = parent;oldIndex = parent.getChildIndex(this);//放大tabwidth = stage.width;height = stage.height;//修正1[当myTab直接加到Application时,再放大]的异常if(!applicationDirectContains(this)){Application.application.addChild(this);}move(0,0);done=true;}else{//还原move(pos.x,pos.y);if(pos.percentWidth)percentWidth = pos.percentWidth;elsewidth = pos.width;if(pos.percentHeight)percentHeight = pos.percentHeight;elseheight = pos.height;oldParent.addChildAt(this,oldIndex);done=false;}}private function applicationDirectContains(child:DisplayObject):Boolean{for(var i:uint=0;i<Application.application.numChildren;i++){if(Application.application.getChildAt(i) == child){return true;}}return false;}}}

不过此工具目前的版本只能于flex sdk3.x下正常工作!

热点排行