Simply put:
I have two png files. I import them using loaders. The images in the png files each have opaque (solid) and transparent parts. I want to use the bitmapdata.hittest method to detect when their opaque parts have collided.
Sadly I have not gotten this to work at all yet...
This is my code:
package
{
import flash.display.*; import flash.events.*;
import flash.geom.*; import flash.text.TextField;
import flash.utils.*; import flash.net.*;
import flash.ui.Mouse; import flash.system.*;
import Math;
public class MAIN extends Sprite
{
private var TEXT:TextField = new TextField();
public var LOADER_1:Loader = new Loader(); public var LOADER_2:Loader = new Loader();
public var BITMAP_1:Bitmap; public var BITMAP_2:Bitmap;
public var DATA_1:BitmapData; public var DATA_2:BitmapData;
public function MAIN()
{
LOADER_2.contentLoaderInfo.addEventListener(Event.COMPLETE,LOADED_2);
LOADER_1.contentLoaderInfo.addEventListener(Event.COMPLETE,LOADED_1);
function LOADED_2(event:Event):void
{
LOADER_2.x = 125; LOADER_2.y = 80;
DATA_2 = new BitmapData(LOADER_2.width,LOADER_2.height,true,0);
DATA_2.draw(LOADER_2);
}
function LOADED_1(event:Event):void
{
LOADER_1.x = mouseX; LOADER_1.y = mouseY;
DATA_1 = new BitmapData(LOADER_1.width,LOADER_1.height,true,0);
DATA_1.draw(LOADER_1);
}
LOADER_2.load(new URLRequest('TEST.png')); addChild(LOADER_2);
LOADER_1.load(new URLRequest('BALL.png')); addChild(LOADER_1);
Mouse.hide(); addChild(TEXT);
stage.frameRate = 60; stage.addEventListener(Event.ENTER_FRAME,STEP);
}
public function STEP(event:Event):void
{
LOADER_1.x = mouseX; LOADER_1.y = mouseY;
if (DATA_1.hitTest(new Point(LOADER_1.x,LOADER_1.y),255,DATA_2,new Point(LOADER_2.x,LOADER_2.y),255))
{TEXT.text = 'hit';} else {TEXT.text = 'miss';}
}
}
}
I've been working on this for a couple of days now and nobody seems to know how to do this. Please don't post the examples on google, I've looked through at least the first five pages of results on google and haven't gotten any of them to work. The problem is that none of them provide an example of using this method with loaders, so I'm guessing the reason I can't get it to work is some gimmick associated with them.