Skip to content

SceneryEvent

Overview

A Scenery event is an abstraction over incoming user DOM events.

It provides more information (particularly Scenery-related information), and handles a single pointer at a time (DOM TouchEvents can include information for multiple touches at the same time, so the TouchEvent can be passed to multiple Scenery events). Thus it is not save to assume that the DOM event is unique, as it may be shared.

NOTE: While the event is being dispatched, its currentTarget may be changed. It is not fully immutable.

@author Jonathan Olson <jonathan.olson@colorado.edu>

Class SceneryEvent

"out" here ensures that SceneryListenerFunctions don't specify a wider type arguments for the event, see https://github.com/phetsims/scenery/issues/1483

import { SceneryEvent } from 'scenerystack/scenery';

Constructor

new SceneryEvent( trail : Trail, type : string, pointer : Pointer, context : EventContext<DOMEvent> )

Instance Methods

handle()

like DOM SceneryEvent.stopPropagation(), but named differently to indicate it doesn't fire that behavior on the underlying DOM event

abort()

like DOM SceneryEvent.stopImmediatePropagation(), but named differently to indicate it doesn't fire that behavior on the underlying DOM event

isFromPDOM() : boolean

Specifies whether the SceneryEvent came from alternative input. See Input.PDOM_EVENT_TYPES for a list of events pdom-related events supported by scenery. These events are exclusively supported by the ParallelDOM for Interactive description.

canStartPress() : boolean

Returns whether a typical PressListener (that isn't already attached) could start a drag with this event.

This can typically be used for patterns where no action should be taken if a press can't be started, e.g.:

down: function( event ) { if ( !event.canStartPress() ) { return; }

// ... Do stuff to create a node with some type of PressListener

dragListener.press( event );

}

NOTE: This ignores non-left mouse buttons (as this is the typical behavior). Custom checks should be done if this is not suitable.

Instance Properties

handled : boolean

Whether this SceneryEvent has been 'handled'. If so, it will not bubble further.

aborted : boolean

Whether this SceneryEvent has been 'aborted'. If so, no further listeners with it will fire.

trail : Trail

(readonly)

Path to the leaf-most node "hit" by the event, ordered list, from root to leaf

type : string

(readonly)

What event was triggered on the listener, e.g. 'move'

pointer : Pointer

(readonly)

The pointer that triggered this event

domEvent : DOMEvent | null

(readonly)

Raw DOM InputEvent (TouchEvent, PointerEvent, MouseEvent,...)

context : EventContext

(readonly)

Assorted environment information when the event was fired

activeElement : Element | null

(readonly)

The document.activeElement when the event was fired

currentTarget : Node | null

Whatever node you attached the listener to, or null when firing events on a Pointer

target : Node

Leaf-most node in trail

isPrimary : boolean

Whether this is the 'primary' mode for the pointer. Always true for touches, and will be true for the mouse if it is the primary (left) mouse button.

Static Properties

SceneryEventIO : IOType

(readonly)

Source Code

See the source for SceneryEvent.ts in the scenery repository.