API Documentation for: 0.6.0
Show:

Utility Methods Class

Defined in: Utility Methods:36
Module: CreateJS

Various utilities that the CreateJS Suite uses. Utilities are created as separate files, and will be available on the createjs namespace directly.

Example

 myObject.addEventListener("change", createjs.proxy(myMethod, scope));

Item Index

Methods

Methods

extend

(
  • subclass
  • superclass
)
Function

Defined in extend:40

Sets up the prototype chain and constructor property for a new class.

This should be called right after creating the class constructor.

function MySubClass() {}
createjs.extend(MySubClass, MySuperClass);
ClassB.prototype.doSomething = function() { }

var foo = new MySubClass();
console.log(foo instanceof MySuperClass); // true
console.log(foo.prototype.constructor === MySubClass); // true

Parameters:

Returns:

Function:

Returns the subclass's new prototype.

indexOf

(
  • array
  • searchElement
)
Number

Defined in indexOf:40

Finds the first occurrence of a specified value searchElement in the passed in array, and returns the index of that value. Returns -1 if value is not found.

 var i = createjs.indexOf(myArray, myElementToFind);

Parameters:

  • array Array

    Array to search for searchElement

  • searchElement Object

    Element to find in array.

Returns:

Number:

The first index of searchElement in array.

promote

(
  • subclass
  • prefix
)
Function

Defined in promote:40

Promotes any methods on the super class that were overridden, by creating an alias in the format prefix_methodName. It is recommended to use the super class's name as the prefix. An alias to the super class's constructor is always added in the format prefix_constructor. This allows the subclass to call super class methods without using function.call, providing better performance.

For example, if MySubClass extends MySuperClass, and both define a draw method, then calling promote(MySubClass, "MySuperClass") would add a MySuperClass_constructor method to MySubClass and promote the draw method on MySuperClass to the prototype of MySubClass as MySuperClass_draw.

This should be called after the class's prototype is fully defined.

function ClassA(name) {
    this.name = name;
}
ClassA.prototype.greet = function() {
    return "Hello "+this.name;
}

function ClassB(name, punctuation) {
    this.ClassA_constructor(name);
    this.punctuation = punctuation;
}
createjs.extend(ClassB, ClassA);
ClassB.prototype.greet = function() {
    return this.ClassA_greet()+this.punctuation;
}
createjs.promote(ClassB, "ClassA");

var foo = new ClassB("World", "!?!");
console.log(foo.greet()); // Hello World!?!

Parameters:

  • subclass Function

    The class to promote super class methods on.

  • prefix String

    The prefix to add to the promoted method names. Usually the name of the superclass.

Returns:

Function:

Returns the subclass.

proxy

(
  • method
  • scope
  • [arg]
)
public static

Defined in proxy:51

A function proxy for methods. By default, JavaScript methods do not maintain scope, so passing a method as a callback will result in the method getting called in the scope of the caller. Using a proxy ensures that the method gets called in the correct scope.

Additional arguments can be passed that will be applied to the function when it is called.

Example

 myObject.addEventListener("event", createjs.proxy(myHandler, this, arg1, arg2));

 function myHandler(arg1, arg2) {
      // This gets called when myObject.myCallback is executed.
 }

Parameters:

  • method Function

    The function to call

  • scope Object

    The scope to call the method name on

  • [arg] Mixed optional
    • Arguments that are appended to the callback for additional params.

Properties

BrowserDetect

Object static

Defined in BrowserDetect:42

An object that determines the current browser, version, operating system, and other environment variables via user agent string.

Used for audio because feature detection is unable to detect the many limitations of mobile devices.

Example

 if (createjs.BrowserDetect.isIOS) { // do stuff }

Sub-properties:

  • isFirefox Boolean

    True if our browser is Firefox.

  • isOpera Boolean

    True if our browser is opera.

  • isChrome Boolean

    True if our browser is Chrome. Note that Chrome for Android returns true, but is a completely different browser with different abilities.

  • isIOS Boolean

    True if our browser is safari for iOS devices (iPad, iPhone, and iPod).

  • isAndroid Boolean

    True if our browser is Android.

  • isBlackberry Boolean

    True if our browser is Blackberry.

definePropertySupported

Boolean

Boolean value indicating if Object.defineProperty is supported.

Example

 if (createjs.definePropertySupported) { // add getter / setter}

Default: true