Collection in Anark Studio 2.5
A collection of items, accessible by index or name.
Inherits from:
Instance Properties
name | type | description |
---|---|---|
constructor | Object | A reference to the constructor class for the current object instance. [from Object] |
length | Number | (read only) Number of items in the collection. |
prototype | Object | The prototype for a class. [from Object] |
Instance Methods
name | returns | description |
---|---|---|
hasOwnProperty(propertyOrMethodName) | Boolean | Determines if the object/instance itself has the named property or method. [from Object] |
isPrototypeOf(instanceToTest) | Boolean | Determines if the calling object prototype is in the inheritance chain for the supplied argument. [from Object] |
propertyIsEnumerable(propertyOrMethodName) | Boolean |
Determines if the object/instance itself has a property or method of the supplied name which will appear in a for (prop in obj) enumeration.
[from Object]
|
toLocaleString() | String |
For most objects, the same as toString() unless explicitly overridden.
[from Object]
|
toString() | String | Returns a string representation of the object. [from Object] |
valueOf() | String |
Returns the internal this value of the object.
[from Object]
|
Description
Collections of items in Anark Studio are used to provide access to child objects of a node. Available collections are scene.layers, someAsset.behaviors, someAsset.sounds, someAsset.music, someNode.cameras, someNode.groups, someNode.lights, someNode.models, someModel.materials, someMaterial.maps.
The instances returned by accessing the above properties do not inherit from a Collection class; for example, scene.layers.constructor
is Object
and not Collection
. Instead, they are custom instances of the Object class with properties and behaviors defined by this page.
Although they are not arrays, collections can be accessed similarly. They have a length
property and integer properties providing access to each child member. For example:
var allLayers = scene.layers;
for ( var i=0, len=allLayers.length; i<len; i++ ){
allLayers[i].transparentBackground = false;
}
In addition to being accessible by index, collections create a property for each named child object, providing access to that object. For example, given the following scene hierarchy…
- Scene
- Layer1
- DiceGroup
- Cube
- Pip1
- Pips2Group
- Pip2_1
- Pip2_2
- …
- DiceGroup
- Layer1
…both of the following code lines to refer to the first pip in the second group:
var pipA = scene.layers[0].groups[0].groups[0].models[0];
var pipB = scene.layers.Layer1.groups.DiceGroup.groups.Pips2Group.models.Pip2_1;
// pipA and pipB refer to the same model.
Finally, you should note that if you want to access objects in the scene hierarchy by name (the more flexible and robust approach), you rarely need to use the collections discussed here. Not only does the runtime engine create named properties for each model in the collections, it also creates the same named properties directly on the parent object itself. For example, a third (terser) way to access "Pip2_1" in the above example is:
var pipC = scene.Layer1.DiceGroup.Pips2Group.Pip2_1;
// a third way to refer to the same model
The collections discussed herein are most useful when you need to iterate every object of a specific type, or when you have given the same name to two child objects of different types. For example, scene.Layer1.Bounce
would be ambiguous in the following hierarchy:
- Scene
- Layer1
- Bounce (a Behavior)
- Bounce (a Sound effect)
- Layer1
In a case like this, the sounds
collection can be used to clarify which object is being referred to, i.e. scene.Layer1.sounds.Bounce
.
Properties that are a Collection
name | object | description |
---|---|---|
behaviors | Asset | (read only) All Behavior objects attached under this asset. |
cameras | Node | (read only) All cameras attached to this object. |
groups | Node | (read only) All groups attached to this object. |
layers | Scene | (read only) All Layer objects in the scene. |
lights | Node | (read only) All lights attached to this node. |
maps | Material | (read only) Images in this material. |
materials | Model | (read only) All materials for this model. |
models | Node | (read only) All models attached to this node. |
music | Asset | (read only) All Music objects attached under this asset. |
sounds | Asset | (read only) All Sounds objects attached under this asset. |