zoukankan      html  css  js  c++  java
  • 透明位图点击处理


    /**
     * Project:                FrameWork
     * Author:                醉人的烟圈(齐小伟)
     * QQ:                        7379076
     * MSN:                        gamefriends@hotmail.com
     * GTalk:                gamefriends.net@gmail.com
     * Email:                gamefriends@qq.com
     * Created:                2012-11-14
     */
    package framework.mouse
    {
            import flash.display.Bitmap;
            import flash.display.BitmapData;
            import flash.events.Event;
            import flash.events.MouseEvent;
            import flash.filters.GlowFilter;
            import flash.geom.Point;
            import flash.geom.Rectangle;
            import flash.utils.Dictionary;
            import flash.utils.getTimer;

            /**
             * 透明位图鼠标事件辅助类
             * 使用方法:
             * 构造传参或BitmapMouseHelper.target = Bitmap
             * @author qixiaowei(Jackie)
             *
             */
            public class BitmapMouseHelper
            {
                    private var _target:Bitmap;
                    private function get bd():BitmapData
                    {
                            return this.target.bitmapData;
                    }
                    public function BitmapMouseHelper(target:Bitmap = null)
                    {
                            this.target = target;
                    }

                    /**
                     * 要处理的位图
                     */
                    public function get target():Bitmap
                    {
                            return _target;
                    }

                    /**
                     * @private
                     */
                    public function set target(value:Bitmap):void
                    {
                            if(value == null && _target){
                                    _target.parent.removeEventListener(MouseEvent.ROLL_OVER, onRollOver);
                                    this.target.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
                            }
                            _target = value;
                            if(_target == null){
                                    return;
                            }
                            if(_target.parent){
                                    onAddedToStage(null);
                            }else{
                                    _target.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
                            }
                    }

                    private function onAddedToStage(event:Event):void
                    {
                            _target.parent.addEventListener(MouseEvent.ROLL_OVER, onRollOver, false, uint.MIN_VALUE);
                    }

                    private function onRollOver(event:MouseEvent):void
                    {
                            this.target.addEventListener(Event.ENTER_FRAME, onEnterFrame);
                    }

                    private function onEnterFrame(event:Event):void
                    {
                            var mousePos:Point = new Point(this.target.stage.mouseX, this.target.stage.mouseY);
                            if(this.target.stage == null || this.target.hitTestPoint(mousePos.x, mousePos.y, true) == false){
                                    this.target.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
                                    this.target.parent.mouseChildren = this.target.parent.mouseEnabled = true;
                                    return;
                            }
                            mousePos = this.target.globalToLocal(mousePos);
                            var hited:Boolean = this.bd.hitTest(new Point(), 255, mousePos, mousePos);
                            this.target.parent.mouseChildren = this.target.parent.mouseEnabled = hited;
                    }
            }
    }

  • 相关阅读:
    Eclipse的下载与安装
    IntelliJ IDEA(2018)安装详解
    关于Idea中的web.xml 自动生成模板问题
    基于ssm框架的web.xml配置及解析
    Mybatis分页插件PageHelper的配置与基本使用
    基于maven的ssm框架pom.xml的基本配置及解析
    python去除字符串中的特殊字符(爬虫存储数据时会遇到不能作为文件名的字符串)
    快速指数算法
    伪随机序列
    django中Queryset的删除问题、分页问题
  • 原文地址:https://www.cnblogs.com/chenhongyu/p/3290629.html
Copyright © 2011-2022 走看看