封装自己的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);
//放大tab
width = 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;
else
width = pos.width;
if(pos.percentHeight)
percentHeight = 100;
else
height = 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);
//放大tab
width = 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;
else
width = pos.width;
if(pos.percentHeight)
percentHeight = pos.percentHeight;
else
height = 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;
}
}
}

[color=red][b]不过此工具目前的版本只能于flex sdk3.x下正常工作![/b][/color]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值