Turns out the main application class doesn't receive mouse events
(O'Reilly AS3 Cookbook recipe 1.6). Not sure why that is.
The problem in my game was that the localToGlobal call was incorrect.
If you mousedown on a Sprite the event target will be the sprite. If
you mousedown on a Shape, the target will be the parent.
I wrote it all up at blog.flexygen.com.

On Wed, Mar 26, 2008 at 2:07 PM, Richard Rodseth <[EMAIL PROTECTED]> wrote:
> I'm clearly missing something basic. In the example below, the
>  mouseDown handler is only reached when I click in the green Sprite,
>  not in the red shape, even though the listener is added to the root.
>  Is there some sort of mask in effect? Or do the Sprite and Shape
>  affect the size of the parent in different ways?
>
>  In the game that I'm working on, I actually have a UIComponent
>  subclass with children which are subclasses of Sprite (because they
>  themselves need a child text object). There, I was finding that the
>  hitTestPoint method wasn't succeeding on the Sprite, but if I made it
>  a Shape, it did succeed. That led me to create this test case.
>
>  Thanks in advance!
>
>  - Richard
>
>  package {
>         import flash.display.Shape;
>         import flash.display.Sprite;
>         import flash.events.MouseEvent;
>         import flash.geom.Point;
>
>         public class hittest extends Sprite
>         {
>                 private var _circleSprite:Sprite;
>                 private var _circleShape:Shape;
>
>                 public function hittest()
>                 {
>                         super();
>                         graphics.beginFill(0xFFFFFF);
>                         graphics.drawRect(0,0,500,500);
>                         graphics.endFill();
>                         this.width = 500;
>                         this.height = 500;
>
>                         _circleSprite = new Sprite();
>                         _circleSprite.graphics.beginFill(0x00FF00);
>                         _circleSprite.graphics.drawRect(0,0,100,100);
>                         _circleSprite.graphics.endFill();
>                         _circleSprite.x = 10;
>                         _circleSprite.y = 10;
>                         addChild(_circleSprite);
>
>                         _circleShape = new Shape();
>                         _circleShape.graphics.beginFill(0xFF0000);
>                         _circleShape.graphics.drawRect(0,0,100,100);
>                         _circleShape.graphics.endFill();
>                         _circleShape.x = 200;
>                         _circleShape.y = 200;
>                         addChild(_circleShape);
>
>                         this.addEventListener(MouseEvent.MOUSE_DOWN, 
> handleMouseDown);
>                 }
>
>                 private function handleMouseDown(event:MouseEvent):void{
>                         trace("mousedown");
>             var selectPoint:Point = localToGlobal(new
>  Point(event.localX, event.localY));
>                         if (_circleSprite.hitTestPoint(selectPoint.x, 
> selectPoint.y, false)) {
>                                 trace("hit sprite");
>                         }
>                         if (_circleShape.hitTestPoint(selectPoint.x, 
> selectPoint.y, false)) {
>                                 trace("hit shape");
>                         }
>                 }
>         }
>  }
>

Reply via email to