views:

28

answers:

0

Okay this is going to be hard to explain, there are a lot of things going on here. Firstly I should mention that I'm not using adobe's creative suite, just notepad and flex to compile. Secondly what I am trying to do is to detect when two externally loaded png images have collided. The images are drawn by two separate classes. The first class is a circle, the second is a maze. Now here is the maze class, which is the simpler of the two:

package
{
    import flash.net.URLRequest;
    import flash.display.*;
    import flash.system.*;
    import flash.events.*;
    import flash.geom.*;
    import Math;
    public class OBJECT_maze extends Sprite
    {
        public var X:Number = 0;    public var Y:Number = 0;
        public var DEPTH:int = 1 ;
        public var CONTAINER:Sprite = new Sprite();
        public var LOADER:Loader = new Loader();
        public var IMAGE:URLRequest = new URLRequest ('TEST.png');
        public function CREATE(CONTAINER:Sprite,X:Number,Y:Number):void
        {
            LOADER.load(IMAGE);
            CONTAINER.stage.addEventListener(Event.ENTER_FRAME,STEP);
            this.CONTAINER = CONTAINER;
            (CONTAINER as MAIN).INSTANCE_LIST[(CONTAINER as MAIN).INSTANCE_LIST.length] = this;
            this.X = X;     LOADER.x = this.X;
            this.Y = Y;     LOADER.y = this.Y;
            DRAW();
        }
        public function STEP(event:Event):void
        {
            SPRITE = BITMAP FUCK U ASHOLE
            DRAW();
        }
        public function DRAW():void 
        {
            (CONTAINER as MAIN).DRAW_LIST[(CONTAINER as MAIN).DRAW_LIST.length] = LOADER;
            (CONTAINER as MAIN).DRAW_LIST[(CONTAINER as MAIN).DRAW_LIST.length] = DEPTH;
        }
    }
}

Now a few different things are going on here that I need to explain. Firstly you will notice that I am loading the png image using a loader. Now notice this bit here:

(CONTAINER as MAIN).INSTANCE_LIST[(CONTAINER as MAIN).INSTANCE_LIST.length] = this;

This loads the instance of the class onto a list in another class (the MAIN class). All this list does is keep a record of all active instances. I will use this list later so its kinda important.

Now see this part here:

(CONTAINER as MAIN).DRAW_LIST[(CONTAINER as MAIN).DRAW_LIST.length] = LOADER;
(CONTAINER as MAIN).DRAW_LIST[(CONTAINER as MAIN).DRAW_LIST.length] = DEPTH;

This helps the main class determine what order to draw things in, it really isn't important. Just pretend that all it is really saying is CONTAINER.addChild(LOADER);

Okay now the next class is pretty complex so I'm only going to show a part of it. Just know that it also loads an external png using a loader in the same way that this class did.

        for (var I:int = 0; I < (CONTAINER as MAIN).INSTANCE_LIST.length; I ++)
        {
            if (getDefinitionByName(getQualifiedClassName((CONTAINER as MAIN).INSTANCE_LIST[I])) == OBJECT_maze)
            {
                               //collision detection needed here
            }
        }

Now the part I posted is under the enterFrame function. Basically the class cycles through all instances until it finds an instance of the maze class. Now at this point I need it perform a collision detection test between its png and the maze's. I've tried using the method found here (assuming no rotation is occuring):

http://www.mikechambers.com/blog/2009/06/24/using-bitmapdata-hittest-for-collision-detection/

But have yet to get it to work. So I guess my problem is I have no idea how to adapt the method in the link to my situation. For one thing I don't know how to convert the data in the loader into bitmapdata. I also don't know how to get/assign the bounds of the images. I've tried manually assigning them (the maze class is 256x256 and the other class is 32x32) but it hasn't worked. Also in the link it is necessary to use the bitmapdata.draw command. Is this actually necessary if I'm not working in adobe's creative suite (somehow the idea has entered my head that I don't need to do this if I'm not)? Also there's the fact that I'm not actually drawing either image here but rather adding it to the display list of the main class earlier on. So can anyone help me in any way?