Class: Layer

layers. Layer

new Layer

Constructor for a Layer object that holds information about a given layer in the current document. There's no need to create an instance of this class directly; rather, you'll retrieve Layer instances through a module:layers.LayerTree instance.

Layer instances have a number of properties that make it easier to understand the layer structure in a document. For instance, layer.parent points to the layer's parent, which is otherwise a chore to figure out using the default API.

This code will display the name of the top-level layer that contains the current layer:

var tree = new layers.LayerTree();
alert(tree.currentLayer.topLayerAncestor.name);
Parameters:
Name Type Description
inConfig Object

An object containing properties that are copied onto the Layer instance.

Source:
  • lib/fwlib/layers.js, line 399
Returns:

A Layer instance representing one of the layers in the current document.

Type
Object

Members

<readonly> allElements :Array

An array of the Fireworks elements and sub-layers that are on the layer in the current state.

Source:
  • lib/fwlib/layers.js, line 546

disclosure :Boolean

Whether the disclosure triangle for the layer in the Layers panel is open or closed

Source:
  • lib/fwlib/layers.js, line 754

<readonly> elements :Array

An array of the Fireworks elements on the layer.

Source:
  • lib/fwlib/layers.js, line 498

<readonly> elemsandsublayers :Array

An array of the Fireworks elements and sub-layers that are on the layer in the current state.

Note that the sub-layers in this array are regular Fireworks layers, not Layer instances. If you want to loop through a layer's elemsandsublayers array and access the Layer instance for each sub-layer you find, you'll need to manually access the sub-layers you find, like so:

var toolbar = new LayerTree().layer("toolbar"),
    elemsandsublayers = toolbar.elemsandsublayers,
    sublayerIndex = 0;

for (var i = 0; i < elemsandsublayers.length; i++) {
    if (elemsandsublayers[i].layerType) {
        // this is a layer object, so look up the corresponding
        // Layer instance in the parent layer's sublayers array
        toolbar.sublayers[sublayerIndex++] // ...
    } else {
        // do something with the regular element
    }
}
Source:
  • lib/fwlib/layers.js, line 532

elemsIndex :Number

The index of this layer in its parent's elemsandsublayers array, or the layer's sublayerIndex if it is a top layer. The elemsandsublayers array is ordered from top to bottom, while the sublayerIndex is ordered from bottom to top.

This index can be used to figure out which element or sub-layer is above or below a given Layer instance in its parent layer.

Note that due to limitations in the Fireworks API, this value will be wrong if the sub-layer has a sibling with exactly the same name and number of elements and sub-layers.

Source:
  • lib/fwlib/layers.js, line 655

index :Number

The index of the layer in the Fireworks layers stack.

Source:
  • lib/fwlib/layers.js, line 434

<readonly> isTopLayer :Boolean

Whether the layer is at the top level of the Layers panel.

Source:
  • lib/fwlib/layers.js, line 780

<readonly> isWebLayer :Boolean

Whether the layer is a web layer.

Source:
  • lib/fwlib/layers.js, line 793

<readonly> layer :Fireworks Layer

The underlying Fireworks layer object that's represented by this Layer instance.

Source:
  • lib/fwlib/layers.js, line 458

<readonly> layerAbove :Layer

The Layer that is immediately above this layer in the Layers panel. This will be null if the layer is at the very top of the stack.

Source:
  • lib/fwlib/layers.js, line 859

<readonly> layerBelow :Layer

The Layer that is immediately below this layer in the Layers panel. This will be null if the layer is at the very bottom of the stack.

Source:
  • lib/fwlib/layers.js, line 895

locked :Boolean

Whether the layer is locked in the Layers panel.

Source:
  • lib/fwlib/layers.js, line 728

name :String

The name of the layer.

Source:
  • lib/fwlib/layers.js, line 474

parent :Layer

The Layer instance that contains this layer.

Source:
  • lib/fwlib/layers.js, line 427

sublayerIndex :Number

The position of the layer among its sub-layer siblings under its immediate parent. If the layer is at the top level, this will be its position among the top-level layers.

Note that this index is from the bottom up, so the bottom-most sub-layer in a layer has a sublayerIndex of 0. This is the reverse order of the native elemsandsublayers array.

Source:
  • lib/fwlib/layers.js, line 447

<readonly> sublayers :[Layer]

An array of the layer's sub-layers, if any. Only immediate sub-layers are returned.

Source:
  • lib/fwlib/layers.js, line 572

<readonly> topLayerAbove :Layer

The top-level Layer that is immediately above the top-level layer that contains this layer. If this layer is at the top of the stack in the Layers panel, than this property will be undefined.

Source:
  • lib/fwlib/layers.js, line 828

<readonly> topLayerAncestor :Layer

The top-level Layer that contains this layer. If this layer is at the top level, then the same layer is returned.

Source:
  • lib/fwlib/layers.js, line 807

<readonly> topLayerBelow :Layer

The top-level Layer that is immediately below the top-level layer that contains this layer. If this layer is at the bottom of the stack in the Layers panel, than this property will be undefined.

Source:
  • lib/fwlib/layers.js, line 844

visible :Boolean

Whether the layer is visible in the document.

Source:
  • lib/fwlib/layers.js, line 703

Methods

deleteAllElements

Deletes all of the child elements on this layer in this state, including all of the children on all of its sub-layers.

Source:
  • lib/fwlib/layers.js, line 952

deleteElements

Deletes the immediate child elements on the layer in this state.

Source:
  • lib/fwlib/layers.js, line 940

remove

Removes the layer from the document. This has the side effect of causing all the other Layer instances in the LayerTree to go "stale", since deleting a layer may cause the other layers in the document to shift their index. Accessing the properties on a stale Layer instance will throw an exception.

Source:
  • lib/fwlib/layers.js, line 926

selectAllElements

Selects all of the child elements on the layer in this state, including all of the children on all of its sub-layers. This is unlike calling dom.selectAllOnLayer(), which selects only the layer's immediate elements, not any elements on any of its sub-layers.

Source:
  • lib/fwlib/layers.js, line 966

setElementLocked

Locks or unlocks a given element in the layer. This method works around the bug in dom.setElementLocked(), which indexes the layer elements in reverse order compared to the dom.layers[0].frames[0].elements array.

Parameters:
Name Type Description
inIndex Number

The index of the element whose locked state you want to change. This is the index of the element in the layer's elements array.

inLocked Boolean

The value to set the locked state to.

Source:
  • lib/fwlib/layers.js, line 1011

setElementVisible

Hides or shows a given element in the layer. This method works around the bug in dom.setElementVisible(), which indexes the layer elements in reverse order compared to the dom.layers[0].frames[0].elements array.

Parameters:
Name Type Description
inIndex Number

The index of the element whose visible state you want to change. This is the index of the element in the layer's elements array.

inVisible Boolean

The value to set the visible state to.

Source:
  • lib/fwlib/layers.js, line 984

sublayer

Returns a Layer instance accessed by its index in the layer's list of immediate sub-layers or by its name. Note that the index is different than the sub-layer's corresponding index in its parent's elemsandsublayers array.

Parameters:
Name Type Description
inIndex Number | String

The 0-based index or name of a sub-layer.

Source:
  • lib/fwlib/layers.js, line 589
Returns:

A Layer instance representing the specified sub-layer, or undefined if it can't be found.

Type
Layer

sublayerByElemsIndex

Returns a Layer instance accessed by its index in the layer's elemsandsublayers array, which is different from the layer's sublayerIndex, since elemsandsublayers contains both layers and elements. You would use this when walking a layer's elemsandsublayers array to access the Layer instance corresponding to a particular sub-layer in that array.

Parameters:
Name Type Description
inIndex Number

The 0-based index of a sub-layer in its parent's elemsandsublayers array.

Source:
  • lib/fwlib/layers.js, line 610
Returns:

A Layer instance representing the specified sub-layer, or undefined if it can't be found.

Type
Layer