MediaBag

Source: MediaBag.js:42

This class stores and manages all the media components (images, sounds, animations, video,
MIDI files, etc.) needed to run the activities of a JClicProject. The main member of
the class is elements. This is where module:bads/MediaBagElement.MediaBagElement objects are stored.


Constructor

new MediaBag( project: module:project/JClicProject.JClicProject, ): MediaBag

MediaBag constructor

Parameters


Instance Methods

setProperties($xml: external:jQuery)

Loads this object settings from a specific JQuery XML element

Parameters

getAttributes(): object

Gets a object with the basic attributes needed to rebuild this instance excluding functions,
parent references, constants and also attributes retaining the default value.
The resulting object is commonly usued to serialize elements in JSON format.

Returns

  • object

setAttributes(data: object)

Loads the MediaBag content from a data object

Parameters

  • data (object) — The data object to parse

getElement( name: string, create?: boolean, ): module:bags/MediaBagElement.MediaBagElement

Finds a module:bads/MediaBagElement.MediaBagElement by its name, creating a new one if not found and requested.

Parameters

  • name (string) — The name of the element
  • create (boolean, optional) — When true, a new MediaBagElement will be created if not found,
    using 'name' as its file name.

Returns

getElementByFileName( file: string, create?: boolean, ): module:bags/MediaBagElement.MediaBagElement

Gets a module:bads/MediaBagElement.MediaBagElement by its file name.

Parameters

  • file (string) — The requested file name
  • create (boolean, optional) — When true, a new module:bads/MediaBagElement.MediaBagElement will be created if not
    found.

Returns

getElementsOfType(type: string): Array.<string>

Get the names of the media elements that are of the given type.
When the search type is font, the fontName property is used instead of name

Parameters

  • type (string) — The type of elements to search

Returns

  • Array.<string>

buildAll( type: string, callback?: function, ps?: module:JClicPlayer.JClicPlayer, ): number

Preloads all resources.

Use with care! Calling this method will start loading all the resources defined in the
MediaBag, whether used or not in the current activity.

Parameters

  • type (string) — The type of media to be build. When null or undefined, all
    resources will be build.
  • callback (function, optional) — Function to be called when each element is ready.
  • ps (module:JClicPlayer.JClicPlayer, optional) — An optional PlayStation (currently a JClicPlayer) used to dynamically load fonts

Returns

  • number

countWaitingElements(): number

Checks if there are media waiting to be loaded

Returns

  • number

getSkinElement(name: string, ps: string): module:skins/Skin.Skin

Loads a Skin object

Parameters

  • name (string) — The skin name to be loaded
  • ps (string) — The JClicPlayer linked to the skin

Returns

Instance Fields

elements: object

The collection of module:bads/MediaBagElement.MediaBagElement objects

project: module:project/JClicProject.JClicProject

The JClic project to which this MediaBag belongs