3

Ives tried many hit detections and none of them seem to work for me. I've tried hittest hittestobject hitarea. When my object (which is a or b movie-clip goes fully into c movie clip i want c to move 300 x direction. Does not need to be pin point detection just as long as its in the c movie-clip it works.

package  {

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.media.Sound;
import flash.ui.Mouse;

public class bakingCake extends MovieClip {


    public function bakingCake() {
        // constructor code

        var object:MovieClip = new MovieClip;

        a.addEventListener(MouseEvent.MOUSE_DOWN,objectA);
        b.addEventListener(MouseEvent.MOUSE_DOWN,objectB);

        if (object.hitArea(c) == true)
        {
                c.x = 300;
        }           

        function objectA():void
        {           
            object = a;             
            object.addEventListener(MouseEvent.MOUSE_OVER,objectFun);
        }

        function objectB():void
        {
            object = b;
            object.addEventListener(MouseEvent.MOUSE_OVER,objectFun);
        }       


        function objectFun(event:MouseEvent):void
        {

            object.addEventListener(MouseEvent.MOUSE_DOWN,drag);
            object.addEventListener(MouseEvent.MOUSE_UP,sDrag);
        }
        function drag(event:MouseEvent):void
        {
            object.startDrag();
        }
        function sDrag(event:MouseEvent):void
        {
            object.stopDrag();

        }

    }
}

}

RacerNerd
  • 1,579
  • 1
  • 13
  • 31
Liam Thomas
  • 71
  • 1
  • 5
  • First of all: Is all this in the constructor function or is that just a copy paste error? What is `c`? What calls the hitArea function? Where are `objectA()` or `objectB()` called? – Rengers Nov 16 '12 at 21:34

1 Answers1

0

Did you tried getBounds() ?
I suggest condition:

if (c.getBounds(c.parent).containsRect(a.getBounds(c.parent))
 || c.getBounds(c.parent).containsRect(b.getBounds(c.parent))) {
    c.x = 300;
}

IMO the best way is check it triggered by ENTER_FRAME event, atached for any of object.

Saram
  • 1,500
  • 1
  • 18
  • 35
  • Question has been solved, Used a stage.addEventListener(Event.ENTER_FRAME, applicationloop); to constantly check collision – Liam Thomas Nov 17 '12 at 12:58