User Guide
Example: SpriteArranger 193
this.selectionIndicator.graphics.drawRect(-1, -1, this.size + 1,
this.size + 1);
this.addChild(this.selectionIndicator);
If this is not the first time the onMouseDown() method is called, the method simply sets the
selectionIndicator shape’s visible property (inherited from the DisplayObject class), as
follows:
this.selectionIndicator.visible = true;
The hideSelected() method hides the selectionIndicator shape of the previously
selected object by setting its
visible property to false.
The
onMouseDown() event handler method also calls the startDrag() method (inherited
from the Sprite class), which includes the following code:
var boundsRect:Rectangle = this.parent.getRect(this.parent);
boundsRect.width -= this.size;
boundsRect.height -= this.size;
this.startDrag(false, boundsRect);
This lets the user drag the selected object around the canvas, within the boundaries set by the
boundsRect rectangle.
When the user releases the mouse button, the
mouseUp event is dispatched. The constructor
method of the DrawingCanvas sets up the following event listener:
this.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
This event listener is set for the DrawingCanvas object, rather than for the individual
GeometricSprite objects. This is because when the GeometricSprite object is dragged, it could
end up behind another display object (another GeometricSprite object) when the mouse is
released. The display object in the foreground would receive the mouse up event but the
display object the user is dragging would not. Adding the listener to the DrawingCanvas
object ensures that the event is always handled.
The
onMouseUp() method calls the onMouseUp() method of the GeometricSprite object,
which in turn calls the
stopDrag() method of the GeometricSprite object.