前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >AS3外部类

AS3外部类

作者头像
py3study
发布2020-01-06 15:18:30
5580
发布2020-01-06 15:18:30
举报
文章被收录于专栏:python3python3

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个实例,就像对象池一样.

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-21 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档