1,注意事项,外部类只能在本文件中的其他类使用,
2,外部类不要写类修饰符
3,外部类写在包外
好处是:
1,可以当做本文件内部类的数据Model,好找.而且看起来更加直观
2,外部代码无法调用,安全性高.但是缺点也比较明显
例:
代码语言:javascript复制package com.upupgame.baccarat.player2.game.views.ui.controls.goodpoint{
import com.greensock.TweenLite;
import com.greensock.easing.Expo;
import com.upupgame.baccarat.player2.assets.GameAssets;
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import flash.geom.Point;
/**
* 点赞(×××)手型管理</br>
* 40225.1
* @author Kayer
* */
public class PraiseThumbsManager{
private static var $instance : PraiseThumbsManager;
public static function get instance() : PraiseThumbsManager{
if( null == $instance ) $instance = new PraiseThumbsManager();
return $instance;
}
/**最高缓存7个模型*/
private const $MAX_CACHE : uint = 7;
private var $modelVs : Vector.<PraiseThumbsModel>;
private var $tweenLife : TweenLite;
private var $isHandleVs : Boolean = false; //是否正在操作列表
public function PraiseThumbsManager(){
if($instance != null){
throw new Error("PraiseThumbsManager 已经被设计成为单例!");
}else{
$modelVs = new Vector.<PraiseThumbsModel>();
$instance = this;
}
}
/**
* 移动大拇指</br>
* 40225.1
* @author Kayer
* */
public function movePraiseThumb($myContainer : DisplayObjectContainer = null,$startPosition : Point = null,
$rootPosition : Point = null,$isMe : Boolean = false) : void{
var $myModel : PraiseThumbsModel = getOneModel(myCallBack,$isMe);
if($myModel != null){
if($myContainer != null ){
$myContainer.addChild($myModel.thumb);
}else{
GameMain.instance.layers.chat.addChild($myModel.thumb);
}
if($startPosition != null ){
$myModel.thumb.x = $startPosition.x;
$myModel.thumb.y = $startPosition.y;
}
if($rootPosition != null ){
$tweenLife = TweenLite.to($myModel.thumb, 1, { y:($rootPosition.y),x:($rootPosition.x),ease:(Expo.easeInOut), onComplete:$myModel.callBack});
}
}else{
Debug.log("40225.1 Kayer 得不到大拇指模型",Debug.RED);
}
}
/***
* 回调函数
* */
private function myCallBack( $value : PraiseThumbsModel) : void{
if($value != null){
remove($value);
if($value.isMe){
PraiseBridePriceStrap.instance.showAndUpdate(false);
}
$value.isIdle = true;
modelsArrange();
}else{
Debug.log("40225.1 Kayer 返回的大拇指模型为Null!",Debug.RED);
}
}
private function remove($value : PraiseThumbsModel ) : void{
if($value != null && $value.thumb != null){
if($value.thumb.parent != null){
$value.thumb.parent.removeChild($value.thumb);
}
}
}
/**
* 整理模型
* */
private function modelsArrange() : void{
if(!$isHandleVs){
for(var $index : int = 0 ; $index < $modelVs.length , $modelVs.length > $MAX_CACHE ; $index = 1){
if($modelVs[$index].isIdle){
$modelVs.splice($index,1);
$index -= 1;
}
}
}
}
/**
* 隐藏所有的动画</br>
* 在退出房间时引用</br>
* 40225.1
* */
public function hideAll() : void{
PraiseBridePriceStrap.instance.showAndUpdate(false);
for(var $index : int = 0 , $len : uint = $modelVs.length ; $index < $len ; $index = 1){
remove($modelVs[$index]);
$modelVs[$index].isIdle = true;
}
$isHandleVs = false;
modelsArrange();
if($tweenLife != null) $tweenLife = null;
}
private function getOneModel( $callBack : Function = null ,$isMe : Boolean = false) : PraiseThumbsModel{
if($modelVs.length <= 0){
return creatOneModel($callBack,$isMe);
}else{
if(!$isHandleVs){
$isHandleVs = true;
var $rootModel : PraiseThumbsModel;
for( var $index : int = 0, $len : uint = $modelVs.length ; $index < $len ; $index = 1){
if($modelVs[$index].isIdle){
$modelVs[$index].isIdle = false;
$modelVs[$index].isMe = $isMe; //更新 自我属性
$rootModel = $modelVs[$index];
break;
}
}
$isHandleVs = false;
if($rootModel != null){
return $rootModel;
}else{
return creatOneModel($callBack,$isMe);
}
}else{
return creatOneModel($callBack,$isMe);
}
}
}
/**
* 制作一个 大拇指
* */
private function creatOneModel( $callBack : Function ,$isMe : Boolean) : PraiseThumbsModel{
var $myModel : PraiseThumbsModel = new PraiseThumbsModel();
$myModel.isIdle = false;
$myModel.isMe = $isMe; //设置自我属性
$myModel.thumb = new GameAssets["PraiseThumb"] as Sprite;
$myModel.callBack = $callBack;
this.$modelVs.push($myModel);
return $myModel;
}
}
}
import flash.display.Sprite;
/***
* 赞大拇指模型</br>
* 40225.1
* @author Kayer
* */
class PraiseThumbsModel{
private var $isIdle : Boolean = true;
private var $thumb : Sprite;
private var $callBack : Function;
private var $isMe : Boolean = false;
public function set isIdle( $value : Boolean ) : void{
this.$isIdle = $value;
}
public function set thumb( $value : Sprite ) : void{
this.$thumb = $value;
}
public function set callBack( $value : Function ) : void{
this.$callBack = $value;
}
public function set isMe($value : Boolean ) : void{
this.$isMe = $value;
}
/**是不是空闲状态*/
public function get isIdle() : Boolean{
return this.$isIdle;
}
/**大拇指实例*/
public function get thumb() : Sprite{
return this.$thumb;
}
/**回调函数*/
public function get callBack() : Function{
return this.myCallBack;
}
/**是不是自己点的赞*/
public function get isMe() : Boolean{
return this.$isMe;
}
private function myCallBack() : void{
if($callBack!= null){
$callBack(this);
}else{
Debug.log("40225.1 Kayer 点赞没有CallBack!",Debug.RED);
}
}
}
另外: 此类,缓存了7个实例,就像对象池一样.