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.

Timer Class

Extends EventDispatcher
Defined in: ts/util/Timer.ts:4
Module: util
Parent Module: StructureJS

Constructs a new Timer object with the specified delay and repeatCount states.

Properties

_listeners Any protected

Holds a reference to added listeners.

_timer Function protected

Defined in ts/util/Timer.ts:19

A reference to the setInterval object.

currentCount Int protected

Defined in ts/util/Timer.ts:28

The total number of times the timer has fired since it started at zero. If the timer has been reset, only the fires since the reset are counted.

delay Number protected

Defined in ts/util/Timer.ts:37

The delay, in milliseconds, between timer events. If you set the delay interval while the timer is running, the timer will restart at the same repeatCount iteration. Note: A delay lower than 20 milliseconds is not recommended.

isEnabled Boolean public

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

Default: false

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.

repeatCount Int protected

Defined in ts/util/Timer.ts:47

The total number of times the timer is set to run. If the repeat count is set to 0, the timer continues indefinitely. If the repeat count is nonzero, the timer runs the specified number of times. If repeatCount is set to a total that is the same or less then currentCount the timer stops and will not fire again.

running Boolean

Defined in ts/util/Timer.ts:56

The timer's current state; true if the timer is running, otherwise false.

sjsId Int public

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

Default: null

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

Timer ()

Defined in ts/util/Timer.ts:4

Methods

_decrementCounter () protected

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);
 }

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();
}

getCurrentCount () Number

Defined in ts/util/Timer.ts:74

Returns the total number of times the timer has fired since it started at zero.

Returns:

Number:

The total number of times the timer has fired since it started at zero.

getDelay () Number

Defined in ts/util/Timer.ts:85

Returns the delay time in milliseconds.

Returns:

Number:

Returns the delay time in milliseconds.

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

getRepeatCount () Number

Returns the total number of times the timer is set to run.

Returns:

Number:

Returns the total number of times the timer is set to run.

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);

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.

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);

reset ()

Stops the timer, if it is running, and sets the currentCount property back to 0, like the reset button of a stopwatch.

setDelay
(
  • value
)

Defined in ts/util/Timer.ts:96

Sets the delay, in milliseconds, between timer events.

Parameters:

setRepeatCount
(
  • value
)

Set the total number of times the timer is set to run. If the repeat count is set to 0, the timer continues indefinitely. If the repeat count is nonzero, the timer runs the specified number of times. If repeatCount is set to a total that is the same or less then currentCount the timer stops and will not fire again.

Parameters:

start ()

Starts the timer, if it is not already running.

stop ()

Stops the timer.

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