dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] AS3 equivilent of HitTest?

  1. #1
    Junior Member
    Join Date
    Aug 2007
    Posts
    23

    resolved [RESOLVED] AS3 equivilent of HitTest?

    Okay. I'm slowly starting to put it all together. I know how to set up a timer for my game's main loop. I know how to attach instances of a movieclip to the stage, and how to safely remove them for garbage collection once they are no longer needed.

    Now all I need is a way to detect when two objects (sprites, graphics, whatever) are overlapping.

    Any suggestions? I've seen how to detect mouse clicks, in the Flash CS3 help file, but that's about it so far...

  2. #2
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361

  3. #3
    Junior Member
    Join Date
    Aug 2007
    Posts
    23
    Ah! Here we go. Thanks, forum Search!

    In AS3 there is no attachment of scripts to any objects allowed any more (fortunately this bad habbit is gone !). You need to associate a class with Symbol1. Also give it a real name. Export for Actionscript. If you don't provide a class, Flash will do it for you.

    Then give your object on the stage a name like mc. The script below does what you wanted.

    Code:
    this.addEventListener(MouseEvent.MOUSE_MOVE, detectObject); 
    function detectObject(e:MouseEvent) 
    { 
        if(hitTestObject(mc)) 
        { 
            mc.alpha +=0.1; 
            if(mc.alpha >= 1) 
            { 
                mc.alpha = 1; 
            } 
        } 
    }
    Sounds like they're not screwing around. AS3 apparently means no more Scripting Language, no more Functional Programming, it's now Advanced OOP or Die!

  4. #4
    Junior Member
    Join Date
    Aug 2007
    Posts
    23
    Oh! Thanks, senocular!

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