captureMouseInput method

void captureMouseInput(
  1. MouseInputData input
)

Captures mouse input and dispatches corresponding mouse events to this display object if it has a touchable area and mouseEnabled is set to true.

The method checks whether the input is captured or not and updates the MouseInputData.captured property accordingly. If the input is newly captured, it also dispatches a MouseInputType.over event to this display object. If the input was already captured, it checks if the mouse is still over this display object and dispatches a MouseInputType.out event if it's not.

The input parameter represents the mouse input data including the input type and position.

Note: This method should not be called directly by user code.

See also:

  • MouseInputData, which represents the mouse input data.
  • mouseEnabled, which indicates whether this display object can receive mouse events.
  • hitTouch, which checks whether a point is within the touchable area of this display object.
  • $dispatchMouseCallback, which dispatches mouse events to this display object.

Implementation

void captureMouseInput(MouseInputData input) {
  if (!$hasTouchableArea) return;
  if (mouseEnabled) {
    if (input.captured && input.type == MouseInputType.up) {
      $mouseDownObj = null;
    }
    var prevCaptured = input.captured;
    globalToLocal(input.stagePosition, input.localPosition);
    input.captured = input.captured ||
        hitTouch(
          input.localPosition,
          mouseUseShape,
        );
    if (!prevCaptured && input.captured) {
      $dispatchMouseCallback(input.type, this, input);
      if ($mouseOverObj != this) {
        $dispatchMouseCallback(MouseInputType.over, this, input);
      }
    } else if ($mouseOverObj == this) {
      $dispatchMouseCallback(MouseInputType.out, this, input);
    }
  }
}