• 透明位图点击处理



    /**
     * 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;
                    }
            }
    }

  • 相关阅读:
    【Spring】构建Spring Web应用
    【记录】Spring项目转化为Spring Web项目
    【生活工具】你能带我回家么,可能明天要下雨了。
    【Spring】面向切面之AOP
    【Spring】高级装配
    【Linux】Linux学习笔记(完结)
    【Spring】Spring的bean装配
    【Netty】源码分析目录
    【项目实战】多线程环境下正确创建单例
    【环境搭建】使用Jekyll搭建Github博客
  • 原文地址:https://www.cnblogs.com/chenhongyu/p/3290629.html
Copyright © 2020-2023  润新知