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