0

When I click on it nothing is being outputted. Is there a reason why the MouseEvent is not being applied to the rectangle. Where am I going wrong?

My Code:

import flash.display.Shape;
import flash.events.MouseEvent;

stop();

var rectangle001:Shape = new Shape;

rectangle001.graphics.beginFill(0x00D783);
rectangle001.graphics.drawRect(10, 10, 50, 50);
rectangle001.addEventListener(MouseEvent.CLICK, rectangle001Click);
function rectangle001Click (event:MouseEvent){
trace("Hello World!");
}
addChild(rectangle001);

All answers appreciated.

1 Answers1

2

You should use Sprite instead of Shape if you want mouse interactivity.

Quoting from an answer on this page:

  • Shape is the one with the least possibilities. Use it when you only want a DisplayObject with graphics, and no mouse interaction.

  • Sprite is the parent class of quite everything you need. Since it is a DisplayObjectContainer, you can use it as a basic container for other components. You can also catch mouse events on this one.

  • MovieClip is a Sprite with the ability to use frames. Only use it for frame-by-frame animation (Flash style).

Community
  • 1
  • 1
Iggy
  • 4,767
  • 5
  • 23
  • 34