A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Hittest not working?

  1. #1
    Always needs help marinebro0306's Avatar
    Join Date
    Jul 2005
    Location
    Philadelphia
    Posts
    166

    Hittest not working?

    I've tried everything, and I can't get hitTest to work.
    I am just experimenting with how to use it, and I have 3 MC's. 1 is called circle, the other star, and the last test. I have the code pasted into 'circle', and test is a little figure that should show when circle and star collide. But, the 'test' MC never shows.

    My script:
    onClipEvent (enterFrame) {
    if (_root.circle, hitTest(_root.star)) {
    setProperty ("_root.test", _visible, true);
    } else {
    setProperty ("_root.test", _visible, false);
    }
    }

    I am using Koolmoves v. 5.0.2, so the previous setProperty problem was resolved. What am I doing wrong???

  2. #2
    Senior Member pherbrick's Avatar
    Join Date
    Jul 2004
    Location
    Los Angeles
    Posts
    291
    You have a typo in your hitTest call.

    Quote Originally Posted by marinebro0306
    if (_root.circle, hitTest(_root.star)) {
    should be
    Quote Originally Posted by marinebro0306
    if (_root.circle.hitTest(_root.star)) {

  3. #3
    Always needs help marinebro0306's Avatar
    Join Date
    Jul 2005
    Location
    Philadelphia
    Posts
    166
    Quote Originally Posted by pherbrick
    You have a typo in your hitTest call.


    should be
    Still doesn't work...I got the script from a tutorial.

    See attached file.
    Attached Files Attached Files

  4. #4
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    not to add to your confusion but if you want to hittest circles it's better to use a distance test rather than hittest as hittest will trigger if the bounding rectangle hits.

    function distance(element1,element2)
    {
    a=element1.x - element2.x;
    b=element1.y - element2.y;
    return sqrt (a*a+b*b);
    }

  5. #5
    Always needs help marinebro0306's Avatar
    Join Date
    Jul 2005
    Location
    Philadelphia
    Posts
    166
    Quote Originally Posted by blanius
    not to add to your confusion but if you want to hittest circles it's better to use a distance test rather than hittest as hittest will trigger if the bounding rectangle hits.

    function distance(element1,element2)
    {
    a=element1.x - element2.x;
    b=element1.y - element2.y;
    return sqrt (a*a+b*b);
    }
    Thanks for the lesson, but I'm still stuck on the hitTest action. When (and if) wo opened the file, could you get it to work? Even with circle shapes clearly intersecting, it would not work.

  6. #6
    Senior Member pherbrick's Avatar
    Join Date
    Jul 2004
    Location
    Los Angeles
    Posts
    291
    To fix:
    1) Remove the second frames from movieclips circle and star,
    2) On the main timeline, use Add Copy of Frame to End,
    3) On Frame 2 of the main timeline, position movieclips circle and star at their farthest point.

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