bags/MediaBag. MediaBag

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)

MediaBag constructor

Parameters:
NameTypeDescription
projectmodule:project/JClicProject.JClicProject

The JClic project to which this media bag belongs

Members

elements :object

The collection of module:bads/MediaBagElement.MediaBagElement objects

Type:
  • object

project :module:project/JClicProject.JClicProject

The JClic project to which this MediaBag belongs

Methods

buildAll(type, callbackopt, psopt) → {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:
NameTypeAttributesDescription
typestring

The type of media to be build. When null or undefined, all
resources will be build.

callbackfunction<optional>

Function to be called when each element is ready.

psmodule:JClicPlayer.JClicPlayer<optional>

An optional PlayStation (currently a JClicPlayer) used to dynamically load fonts

Returns:
  • The total number of elements that will be built
Type: 
number

countWaitingElements() → {number}

Checks if there are media waiting to be loaded

Returns:
  • The amount of media elements already loaded, or -1 if all elements are ready
Type: 
number

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:
  • The resulting object, with minimal attrributes
Type: 
object

getElement(name, createopt) → {module:bags/MediaBagElement.MediaBagElement}

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

Parameters:
NameTypeAttributesDescription
namestring

The name of the element

createboolean<optional>

When true, a new MediaBagElement will be created if not found,
using 'name' as its file name.

getElementByFileName(file, createopt) → {module:bags/MediaBagElement.MediaBagElement}

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

Parameters:
NameTypeAttributesDescription
filestring

The requested file name

createboolean<optional>

When true, a new module:bads/MediaBagElement.MediaBagElement will be created if not
found.

getElementsOfType(type) → {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:
NameTypeDescription
typestring

The type of elements to search

Returns:
Type: 
Array.<string>

getSkinElement(name, ps) → {module:skins/Skin.Skin}

Loads a Skin object

Parameters:
NameTypeDescription
namestring

The skin name to be loaded

psstring

The JClicPlayer linked to the skin

Returns:
Type: 
module:skins/Skin.Skin

setAttributes(data)

Loads the MediaBag content from a data object

Parameters:
NameTypeDescription
dataobject

The data object to parse

setProperties($xml)

Loads this object settings from a specific JQuery XML element

Parameters:
NameTypeDescription
$xmlexternal:jQuery

The XML element to parse