0
votes

in my AS3 Code I have added this simple EventListener:

addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);

there are no errors or anything else, but when I trace something in my mouseMoveHandler it doesn't export something to my console

protected function mouseMoveHandler(event:MouseEvent):void
        {
            trace("mouseMoved")
        }

First I thought this problem shouldn't be so difficult, and I suspect that this has something to do with the stage (addEventListener isn't at the top of it). When I googled it I found something about bubbling, but this just works with dispatch Event or? Thank you in advance for your help!

1
Ideally, this should've worked. You'd need to post more code to figure out the real issue.catholicon
yes I also thought about this, but the code might be a bit confusing and I would also have to copy 3 classes to understand everything thats why I thougth maybe there could be general problems with that?Babsi
Hmm...do check out if is this instannce on the displayList (it's parent.parent.... would lead to stage)? ... you can trace the stage property to verify it without wading through the codecatholicon

1 Answers

1
votes

The stage itself doesn't dispatch a mouseMove - actually i didn't know about it. You rarely work with the stage directly. It works whit a child though as expected.

package
{
  import flash.display.Sprite;
  import flash.events.MouseEvent;

  public class TheMouse extends Sprite
  {
    public function TheMouse()
    {
      addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);

      const background:Sprite = new Sprite();
      background.graphics.beginFill(0);
      background.graphics.drawRect(0, 0, 100, 100);
      background.graphics.endFill();
      addChild(background);
    }

    private function mouseMoveHandler(event:MouseEvent):void
    {
      trace('mouseMoveHandler');
    }
  }
}