dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Help mme

  1. #1
    Junior Member
    Join Date
    Apr 2007
    Posts
    9

    Help mme

    I use flash 2004, and I want to know if there is code that makes it so that if a button hits another button, I can make an event like gotoAndPlay happen. Thanks.

  2. #2
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    Detecting collisions
    The hitTest() method of the MovieClip class detects collisions in a SWF file. It checks to see if an object has collided with a movie clip and returns a Boolean value (true or false).

    There are two cases in which you would want to know whether a collision has occurred: to test if the user has arrived at a certain static area on the Stage or to determine when one movie clip has reached another. With hitTest(), you can determine these results.

    You can use the parameters of hitTest() to specify the x and y coordinates of a hit area on the Stage or use the target path of another movie clip as a hit area. When specifying x and y, hitTest() returns true if the point identified by (x, y) is a non-transparent point. When a target is passed to hitTest(), the bounding boxes of the two movie clips are compared. If they overlap, hitTest() returns true. If the two boxes do not intersect, hitTest() returns false.

    Move the pointer over the shape in the SWF file to test the collision. The results of the hitTest() method are returned in the text field.



    You can also use hitTest() to test a collision between two movie clips.

    To test the collision, drag the car movie clip so that it touches the parking area movie clip. The results of the hitTest() method are returned in the text field.



    The following procedures show how to detect collision using the car example.

    To detect a collision between a movie clip and a point on the Stage:
    Create a new movie clip on the Stage, and enter box_mc as the instance name in the Property inspector.
    Select the first frame on Layer 1 in the Timeline.
    Select Window > Development Panels > Actions to open the Actions panel, if it is not already open.
    Add the following code in the Actions panel:
    this.createTextField("status_txt", 999, 0, 0, 100, 22);
    status_txt.border = true;

    box_mc.onEnterFrame = function() {
    status_txt.text = this.hitTest(_xmouse, _ymouse, true);
    };

    Select Control > Test Movie, and move the pointer over the movie clip to test the collision.
    The value true appears whenever the pointer is over a non-transparent pixel.

    To perform collision detection on two movie clips:
    Drag two movie clips to the Stage, and give them the instance names car_mc and area_mc.
    Select the first frame on Layer 1 in the Timeline.
    Select Window > Development Panels > Actions to open the Actions panel, if it is not already visible.
    Enter the following code in the Actions panel:
    this.createTextField("status_txt", 999, 10, 10, 100, 22);
    area_mc.onEnterFrame = function() {
    status_txt.text = this.hitTest(car_mc);
    };

    car_mc.onPress = function() {
    this.startDrag(false);
    updateAfterEvent();
    };
    car_mc.onRelease = function() {
    this.stopDrag();
    };

    Select Control > Test Movie, and drag the movie clip to test the collision detection.
    Whenever the bounding box of the car intersects the bounding box of the area, the status is true.

    For more information, see MovieClip.hitTest() in Flash ActionScript Language Reference.

    hit test is what you are looking for

    IMS

  3. #3
    Junior Member
    Join Date
    Apr 2007
    Posts
    9
    Thanks, this helped me a lot, but if I wanted to make it so that the hitTest was true, a gotoAndPlay event would happen, how would I do it?

  4. #4
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    if (myMovie1_mc.hitTest(drophere_mc)) {
    myMovie2_mc.gotoAndPlay(7);
    } else {
    // do this
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center