Collission detection/response acts weird

I’m experimenting with more interesting titles to see if that will get a response.

I need a hand. I’ve tried everything I can to make this work. I’ve finally cleared up all errors, but it just doesn’t work right. Collision response is inconsistent and irrational. Collision is frequently not detected. And collision response to a release outside of the target removes the object from the stage, instead of returning it back to the original position.

This is my first “successful” AS3 OOP project, but it is unusable and I’m falling behind in my work. So if someone could help me out, I would really appreciate it.

I’ll paste the code here and attach the files as well.

The main .as:

package
{
    //every built-in function requires an import some of these serve more than one (e.g., ...MovieClip)
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFormat;
    //DragDrop holds the code for the drag/drop action
    import DragDrop;
    //These are the objects to be dragged
    import DA;
    import DB;
    import DC;
    import DD;
    import DE;
    import DF;
    
    public class DragExercise extends MovieClip
    {
        //Making a variable so we can reference the drag objects
        private var da:DA;
        private var db:DB;
        private var dc:DC;
        private var dd:DD;
        private var de:DE;
        private var df:DF;
        private var orig_X:Number;
        private var orig_Y:Number;
        /*private var db_orig_X:Number;
        private var db_orig_Y:Number;
        private var dc_orig_X:Number;
        private var dc_orig_Y:Number;
        private var dd_orig_X:Number;
        private var dd_orig_Y:Number;
        private var de_orig_X:Number;
        private var de_orig_Y:Number;
        private var df_orig_X:Number;
        private var df_orig_Y:Number;*/
        private var _totalPieces:Number;
        private var _currentPieces:Number;
        
                
        
        public function DragExercise()
        {
            _totalPieces = 6;
            _currentPieces = 0;
            createPieces();
            setSuccessMessage();
        }
        
        private function createPieces():void
        {
            //create an instance of the dragable piece, position it, 
            da = new DA();
            addChild(da);
            //identify its target  
            da._targetPiece = ha_mc;
            da.x = 452.6;
            da.y = 42.2;
            //This captures original position, but I'm not sure what to do with it yet
            /*da.orig_X = 413.4;
            da.orig_Y = 42.2;*/
            //Create a listener that listens for the mouse and point flash to instruction for respons
            da.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
            
            db = new DB();
            addChild(db);
            db._targetPiece = hb_mc;
            db.x = 248.7
            db.y = 42.2;
            /*db.orig_X = 229.1;
            db.orig_Y = 42.2;*/
            db.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
            
            dc = new DC();
            addChild(dc);
            dc._targetPiece = hc_mc;
            dc.x = 146.7;
            dc.y = 42.2;
            /*dc.orig_X = 136.9;
            dc.orig_Y = 42.2;*/
            dc.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
            
            dd = new DD();
            addChild(dd);
            dd._targetPiece = hd_mc;
            dd.x = 554.7;
            dd.y = 42.2;
            /*dd.orig_X = 554.7;
            dd.orig_Y = 42.2;*/
            dd.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
            
            
            de = new DE();
            addChild(de);
            de._targetPiece = he_mc;
            de.x = 44.8;
            de.y = 42.2;
            /*de.orig_X = 44.8;
            de.orig_Y = 42.2;*/
            de.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
            
            df = new DF();
            addChild(df);
            df._targetPiece = hf_mc;
            df.x = 350.6;
            df.y = 42.2;
            /*df.orig_X = 350.6;
            df.orig_Y = 42.2;*/
            df.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
        }
        
        private function checkTarget(event:MouseEvent):void
        //The listener tells flash to go here for instructions when the object is released after a drag
        {
            if(event.currentTarget.hitTestObject(event.currentTarget._targetPiece))
            {
                //This clever code tells the piece to position itself exactly over the target if the drage touches the target piece
                event.currentTarget.x = event.currentTarget._targetPiece.x;
                event.currentTarget.y = event.currentTarget._targetPiece.y;
                //since each drag object has its own listener, we want to remove these when done 
                //(otherwise they might move them to the wrong position)
                event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, checkTarget);
                event.currentTarget.disable();
                //if all pieces are in place, the game is over._
                _currentPieces ++;
                if(_currentPieces >= _totalPieces)
                
                {
                    trace("good job");
                    //winMSG.text = "That's right. (You know your business!)";
                }
            }
            else
            {
                //else put the piece back to its starting point
                event.currentTarget.x = event.currentTarget.orig_X;
                event.currentTarget.y = event.currentTarget.orig_Y;
                trace("I'm sending this back to " + orig_X + "and " + orig_Y);
            }
            
        }
        private function setSuccessMessage():void
        {
            var myFormat:TextFormat = new TextFormat();
            myFormat.font = "Verdana";
            myFormat.size = 16;
            myFormat.color = 0x000066;
                
            var winMSG:TextField = new TextField();
            addChild(winMSG);
            winMSG.x = 90;
            winMSG.y = 100;
            winMSG.text ="";
            winMSG.width = 374.8
            winMSG.setTextFormat(myFormat);
        }
    }
}

The drag/drop code:

package
{
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    
    public class DragDrop extends MovieClip
    {
        public var _targetPiece:*;
        public var _origX:Number;
        public var _origY:Number;
        
        public function DragDrop()
        {
            /*_origX = this.x;
            _origY = this.y;*/
            trace("This object started at " + _origX +" and "+ _origY);
            this.addEventListener(MouseEvent.MOUSE_DOWN, dragMovie);
            this.addEventListener(MouseEvent.MOUSE_UP, dropMovie);
            this.buttonMode = true;
        }
        
        private function dragMovie(event:MouseEvent):void
        {
            this.startDrag();
        }
        
        private function dropMovie(event:MouseEvent):void
        {
            this.stopDrag();
        }
        
        public function disable():void
        {
            this.buttonMode = false;
            this.removeEventListener(MouseEvent.MOUSE_DOWN, dragMovie);
            this.removeEventListener(MouseEvent.MOUSE_UP, dropMovie);
        }
    }
}