Menu

Globals

Winston Tamblyn

Globals

This section provides you with information on the global properties and methods added to the global scope.

embed

The embed function is used to embed assets into the application. Assets are available through the global scope via the name parameter after CraveJs has finished loading.

The embed function has a few different forms:

Embeding Images

embed(name, url);

The first parameter given is the name you want associated with the loaded asset. This allows you to access the asset from anywhere in your code. The url parameter specifies the location of the image and must end with one of the following: png, bmp, gif, jpeg, or svg.

Embeding Sounds

embed(name, ["path/to/firstUrl", "path/to/secondUrl", ...]);

The first parameter is used the same as before, but the second parameter is a array containing urls that lead to a couple sound files. If one sound format is not supported by the browser, the second sound file will attempt to be loaded in it's place, and continues until it finds one it thinks it can play.

Calling All Assets

The last variety allows you to embed all your assets in one embed call. Just pass an object containing the name => value pairs describing the assets. The name being the variable you can access the asset from and the value being the url or list of urls to load the asset from.

example :

embed({
    bmdCar : "lib/img/car.png",
    sndHonk : ["lib/sfx/honk.wav", "lib/sfx/honk.mp3"]
});

package

The package function provides the developer with a means to create, extend, and organize one's custom created classes. It takes an object with name => value pairs that correspond to the class name and it's construct object, respectfully, and a location to store the class (optional).

package has two forms:

package(directory, classList);

The first option allows you to specify a directory to store the class. This is a string value that represents the location of a class. This is primarily used to organize your code.

The second parameter is an object that contains one or more class constructs. Even though you can supply more than one construct, you can't extend a class that is part of the same package call as the child class. Define parent classes in a seperate package call before creating the child class.

and package(classList);

The second option's classList has the same restrictions as the first option, but adds the classes directly to the global scope.

The classList can be a function as long as it returns the list of objects to be packaged.


Related

Wiki: CraveJs
Wiki: Getting Started