1. /** 
  2.                  *鼠标事件  
  3.                  * @param evt 
  4.                  *  
  5.                  */                  
  6.                   
  7.                 private function mouseDownHandler(evt:MouseEvent):void  
  8.                 {  
  9.                          if(evt.currentTarget is SceneObject)  
  10.                         {                  
  11.                                 //判断当前点击区是否在最小图形范围内  
  12.                                   
  13.                                 var bmd:BitmapData = new BitmapData(evt.currentTarget.width,evt.currentTarget.height,true0x00000000);  
  14.                                 bmd.draw(evt.currentTarget as SceneObject);  
  15.                                                                    
  16.                                                                 //第一种方法:找到对象的非空白区域,判断鼠标点击点是否在该区域内  
  17.   
  18.                                 ///看帮助 若要确定图像周围的空白区域,请传递 {mask: 0xFFFFFFFF, color: 0xFFFFFFFF} 以查找非空白像素的范围。如果new BitmapData时填充了 0x00000000则传递{mask: 0xFFFFFFFF, color: 0x00000000}  
  19.                                 /*var rect:Rectangle = bmd.getColorBoundsRect(0xffffffff,0x00000000,false);         
  20.                                 trace(rect); 
  21.                                 var minx:Number =  rect.x; 
  22.                                 var miny:Number =  rect.y; 
  23.                                 var maxx:Number = minx + rect.width; 
  24.                                 var maxy:Number = miny + rect.height; 
  25.                                 */  
  26.   
  27.                                                                 //第二种方法 取当前点击点的颜色值 与0x0000000进行判断如果相等则非空白 ,  
  28.                                 /*var color:uint = bmd.getPixel32(evt.localX,evt.localY); 
  29.                                 trace(color.toString(16),0x00000000); //此处 的color值在点击透明区域输出0xffffffff 
  30.                                 */  
  31.   
  32.                                                                  //第三种方法 利用像素碰撞函数hitTest一步解决 0x00000001 为取比0x00000000都大的区域都为非透明像素  
  33.                                 var ptoint = new Point(evt.localX,evt.localY);   
  34.                                 if(bmd.hitTest(new Point(0,0),0x00000001,pt))  
  35.                                 //if(evt.localX>= minx  && evt.localX <= maxx && evt.localY  >= miny  && evt.localY <= maxy)  
  36.                                 //if(color != 0x00000000)  
  37.                                 {  
  38.                                         trace("按下,在内部");  
  39.                                                                                 bmd.dispose();  
  40.                                 }  
  41.                                 else  
  42.                                 {  
  43.                                         trace("按下,不在内部");  
  44.                                         bmd.dispose();  
  45.                                         return;//返回不停止事件流,让鼠标托动背景   
  46.                                 }                        }  
  47.                         evt.stopPropagation();  
  48.                 }  
posted on 2018-07-04 17:46  凌落成迷  阅读(196)  评论(0编辑  收藏  举报