StructureJS

0.15.2

A class based utility library for building modular and scalable web platform applications. Features opt-in classes and utilities which provide a solid foundation and toolset to build your next project.

DisplayObjectContainer Class

Extends DisplayObject
Module: view
Parent Module: StructureJS

The DisplayObjectContainer class is the base class for all objects that can be placed on the display list.

Properties

_listeners Any protected

Holds a reference to added listeners.

alpha Number public

Indicates the alpha transparency value of the object specified.

children Array. public

A reference to the child DisplayObject instances to this parent object instance.

ctx CanvasRenderingContext2D public

The CanvasRenderingContext2D interface provides the 2D rendering context for the drawing surface of a canvas element. This property is only used with the canvas specific display objects.

height Number public

Indicates the height of the display object, in pixels.

Default: 0

isCreated Boolean public

The isCreated property is used to keep track if it is the first time this DisplayObject is created.

Default: false

isEnabled Boolean public

The isEnabled property is used to keep track of the enabled state of the object.

Default: false

mouseChildren Boolean public

Determines whether or not the children of the object are mouse enabled.

mouseEnabled Boolean public

Specifies whether this object receives mouse

name String public

Indicates the instance name of the DisplayObject.

numChildren Int public

Returns the number of children of this object.

Default: 0

parent Any public

Indicates the object that contains a child object. Uses the parent property to specify a relative path to display objects that are above the current display object in the display list hierarchy and helps facilitate event bubbling.

rotation Number public

Indicates the rotation of the DisplayObject instance, in degrees, from its original orientation.

scaleX Number public

Indicates the horizontal scale (percentage) of the object as applied from the registration point.

scaleY Number public

Indicates the vertical scale (percentage) of an object as applied from the registration point of the object.

sjsId Int public

The sjsId (StructureJS ID) is a unique identifier automatically assigned to most StructureJS objects upon instantiation.

Default: null

stage Any public

The Stage of the display object.

unscaledHeight Number public

A property providing access to the unscaledHeight.

Default: 100

unscaledWidth Number public

A property providing access to the unscaledWidth.

Default: 100

useHandCursor Boolean public

A Boolean value that indicates whether the pointing hand (hand cursor) appears when the pointer rolls over a display object.

visible Boolean public

Whether or not the display object is visible.

width Number public

Indicates the width of the display object, in pixels.

Default: 0

x Number public

A property providing access to the x position.

Default: 0

y Number public

A property providing access to the y position.

Default: 0

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

Constructor

DisplayObjectContainer ()

Methods

addChild
(
  • child
)
DisplayObjectContainer public chainable

Adds a child DisplayObject instance to this parent object instance. The child is added to the front (top) of all other children in this parent object instance. (To add a child to a specific index position, use the addChildAt() method.)

If you add a child object that already has a different parent, the object is removed from the child list of the other parent object.

Parameters:

  • child DisplayObject

    The DisplayObject instance to add as a child of this DisplayObjectContainer instance.

Returns:

DisplayObjectContainer:

Returns an instance of itself.

addChildAt
(
  • child
  • index
)
DisplayObjectContainer public chainable

Adds a child DisplayObject instance to this DisplayObjectContainerContainer instance. The child is added at the index position specified. An index of 0 represents the back (bottom) of the display list for this DisplayObjectContainerContainer object.

Parameters:

  • child DisplayObject

    The DisplayObject instance to add as a child of this object instance.

  • index Int

    The index position to which the child is added. If you specify a currently occupied index position, the child object that exists at that position and all higher positions are moved up one position in the child list.

Returns:

DisplayObjectContainer:

Returns an instance of itself.

addEventListener
(
  • type
  • callback
  • scope
  • [priority=0]
)
public chainable

Registers an event listener object with an EventDispatcher object so the listener receives notification of an event.

Parameters:

  • type String

    The type of event.

  • callback Function

    The listener function that processes the event. This function must accept an Event object as its only parameter and must return nothing, as this example shows. @example function(event:Event):void

  • scope Any

    Binds the scope to a particular object (scope is basically what "this" refers to in your function). This can be very useful in JavaScript because scope isn't generally maintained.

  • [priority=0] Int optional

    Influences the order in which the listeners are called. Listeners with lower priorities are called after ones with higher priorities.

Example:

 this.addEventListener(BaseEvent.CHANGE, this._handlerMethod, this);

 _handlerMethod(event) {
     console.log(event.target + " sent the event.");
     console.log(event.type, event.data);
 }

addEventListenerOnce
(
  • type
  • callback
  • scope
  • [priority=0]
)
public chainable

Registers an event listener object once with an EventDispatcher object so the listener will receive the notification of an event.

Parameters:

  • type String

    The type of event.

  • callback Function

    The listener function that processes the event. This function must accept an Event object as its only parameter and must return nothing, as this example shows. @example function(event:Event):void

  • scope Any

    Binds the scope to a particular object (scope is basically what "this" refers to in your function). This can be very useful in JavaScript because scope isn't generally maintained.

  • [priority=0] Int optional

    Influences the order in which the listeners are called. Listeners with lower priorities are called after ones with higher priorities.

Example:

 this.addEventListenerOnce(BaseEvent.CHANGE, this._handlerMethod, this);

 _handlerMethod(event) {
     console.log(event.target + " sent the event.");
     console.log(event.type, event.data);
 }

contains
(
  • child
)
Boolean public

Determines whether the specified display object is a child of the DisplayObject instance or the instance itself. The search includes the entire display list including this DisplayObject instance.

Parameters:

Returns:

Boolean:

true if the child object is a child of the DisplayObject or the container itself; otherwise false.

create () DisplayObject public chainable

The create function is intended to provide a consistent place for the creation or initializing the view. It will automatically be called the first time that the view is added to a DisplayObjectContainer. It is critical that all subclasses call the super for this function in their overridden methods.

Returns:

DisplayObject:

Returns an instance of itself.

destroy () Void public

The purpose of the destroy method is to make an object ready for garbage collection. This should be thought of as a one way function. Once destroy is called no further methods should be called on the object or properties accessed. It is the responsibility of those who implement this function to stop all running Timers, all running Sounds, and take any other steps necessary to make an object eligible for garbage collection.

By default the destroy method will null out all properties of the class automatically. You should call destroy on other objects before calling the super.

Returns:

Void:

Example:

destroy() {
     this.disable();

     this._childInstance.destroy();

     super.destroy();
}

disable () public chainable

The disable method is responsible for disabling event listeners and/or children of the containing objects.

Example:

 disable() {
     if (this.isEnabled === false) { return; }

     this._childInstance.removeEventListener(BaseEvent.CHANGE, this.handlerMethod, this);
     this._childInstance.disable();

     super.disable();
 }

dispatchEvent
(
  • event
  • [data=null]
)
public chainable

Dispatches an event into the event flow. The event target is the EventDispatcher object upon which the dispatchEvent() method is called.

Parameters:

  • event String | BaseEvent

    The Event object or event type string you want to dispatch. You can create custom events, the only requirement is all events must extend BaseEvent.

  • [data=null] Any optional

    The optional data you want to send with the event. Do not use this parameter if you are passing in a BaseEvent.

Example:

 this.dispatchEvent('change');

 // Example: Sending data with the event:
 this.dispatchEvent('change', {some: 'data'});

 // Example: With an event object
 // (event type, bubbling set to true, cancelable set to true and passing data) :
 let event = new BaseEvent(BaseEvent.CHANGE, true, true, {some: 'data'});
 this.dispatchEvent(event);

 // Here is a common inline event object being dispatched:
 this.dispatchEvent(new BaseEvent(BaseEvent.CHANGE));

enable () public chainable

The enable method is responsible for enabling event listeners and/or children of the containing objects.

Example:

enable() {
     if (this.isEnabled === true) { return; }

     this._childInstance.addEventListener(BaseEvent.CHANGE, this.handlerMethod, this);
     this._childInstance.enable();

     super.enable();
}

getChildAt
(
  • index
)
DisplayObject

Returns the child display object instance that exists at the specified index.

Parameters:

  • index Int

    The index position of the child object.

Returns:

DisplayObject:

The child display object at the specified index position.

getChildByCid
(
  • sjsId
)
DisplayObject | Null public

Gets a DisplayObject by its sjsId.

Parameters:

Returns:

DisplayObject | Null:

getChildIndex
(
  • child
)
Int public

Returns the index position of a child DisplayObject instance.

Parameters:

Returns:

Int:

The index position of the child display object to identify.

getEventListeners () Array public

Returns and array of all current event types and there current listeners.

Returns:

Array:

Example:

 this.getEventListeners();

getQualifiedClassName () String public

Returns the fully qualified class name of an object.

Returns:

String:

Returns the class name.

Example:

let someClass = new SomeClass();
someClass.getQualifiedClassName();

// SomeClass

hasEventListener
(
  • type
  • callback
  • scope
)
Boolean public

Check if an object has a specific event listener already added.

Parameters:

  • type String

    The type of event.

  • callback Function

    The listener method to call.

  • scope Any

    The scope of the listener object.

Returns:

Example:

 this.hasEventListener(BaseEvent.CHANGE, this._handlerMethod, this);

layout
(
  • ...rest
)
DisplayObject public chainable

The layout method provides a common function to handle updating objects in the view.

Parameters:

  • ...rest Array

Returns:

DisplayObject:

Returns an instance of itself.

print () String public

Prints out each event listener in the console.log

Returns:

Example:

 this.printEventListeners();

 // [ClassName] is listening for the 'BaseEvent.change' event.
 // [AnotherClassName] is listening for the 'BaseEvent.refresh' event.

removeChild
(
  • child
)
DisplayObjectContainer public chainable

Removes the specified child object instance from the child list of the parent object instance. The parent property of the removed child is set to null , and the object is garbage collected if no other references to the child exist. The index positions of any objects above the child in the parent object are decreased by 1.

Parameters:

Returns:

DisplayObjectContainer:

Returns an instance of itself.

removeChildren () DisplayObjectContainer public chainable

Removes all child DisplayObject instances from the child list of the DisplayObjectContainerContainer instance. The parent property of the removed children is set to null , and the objects are garbage collected if no other references to the children exist.

Returns:

DisplayObjectContainer:

Returns an instance of itself.

removeEventListener
(
  • type
  • callback
  • scope
)
public chainable

Removes a specified listener from the EventDispatcher object.

Parameters:

  • type String

    The type of event.

  • callback Function

    The listener object to remove.

  • scope Any

    The scope of the listener object to be removed.

Example:

 this.removeEventListener(BaseEvent.CHANGE, this._handlerMethod, this);

swapChildren
(
  • child1
  • child2
)
DisplayObjectContainer public chainable

Swaps two DisplayObject's with each other.

Parameters:

Returns:

DisplayObjectContainer:

Returns an instance of itself.

swapChildrenAt
(
  • index1
  • index2
)
DisplayObjectContainer public chainable

Swaps child objects at the two specified index positions in the child list. All other child objects in the display object container remain in the same index positions.

Parameters:

  • index1 Int

    The index position of the first child object.

  • index2 Int

    The index position of the second child object.

Returns:

DisplayObjectContainer:

Returns an instance of itself.

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index