+展开-ActionScript
public function hitTest(firstPoint:Point, firstAlphaThreshold:uint, secondObject:Object, secondBitmapDataPoint:Point = null, secondAlphaThreshold:uint = 1):Boolean
+展开-XML
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="1500"
height="900">
<mx:Script>
<![CDATA[
import flash.display.BlendMode;
private var mainBmp:BitmapData;
private var dragBmp:BitmapData;
private var hasDrawn:Boolean = false;
private function loaded():void{
if(!hasDrawn){
mainBmp = new BitmapData(
mainImg.width, mainImg.height,true,0x00000000);
dragBmp = new BitmapData(
dragImg.width, dragImg.height, true, 0x00000000);
hasDrawn = true;
this.addEventListener(Event.ENTER_FRAME, showHits);
}
}
private function showHits(event:Event):void
{
mainBmp.draw(mainImg);
dragBmp.draw(dragImg);
if(mainBmp.hitTest(new Point(0,0), 0xff,
dragImg.getBounds(this).topLeft)){
trace(" true ");
return;
}
if(mainBmp.hitTest(new Point(0,0), 0xff,
dragImg.getBounds(this). bottomRight)){
trace(" true ");
return;
}
if(mainBmp.hitTest(new Point(0,0), 0xff, new
Point(dragImg.getBounds(this).left,
dragImg.getBounds(this).bottom))){
trace(" true ");
return;
}
if(mainBmp.hitTest(new Point(0,0), 0xff, new
Point(dragImg.getBounds (this).right,
dragImg.getBounds(this).top))){
trace(" true ");
return;
}
trace(" false ");
}
]]>
</mx:Script>
<mx:Image id="mainImg" source="../assets/alphapng.png"
cacheAsBitmap="true"/>
<mx:Image cacheAsBitmap="true" id="dragImg"
mouseDown="dragImg.startDrag(false, this.getBounds(stage)),
loaded()" rollOut="dragImg.stopDrag()"
mouseUp="dragImg.stopDrag()"
source="../assets/bigshakey.png"/>
</mx:Canvas>