Class: LayerTree

layers. LayerTree

new LayerTree

Constructor for a LayerTree object that holds information about the current state of all the layers in the current document. To use it, just create a new instance:

var tree = new layers.LayerTree();
// shows index of layer named "Dialog"
alert(tree.layer("Dialog").index);

The LayerTree is generated for the layers on the current frame of the document. Change dom.currentFrameNum before creating a new LayerTree to get the layers on a different frame. Due to bugs in the layers API, if you change dom.currentFrameNum after creating the LayerTree, the wrong layer is likely to be returned or modified when accessing a layer by name or index.

The LayerTree members return instances of the module:layers.Layer class.

Parameters:
Name Type Argument Default Description
inDOM Object <optional>
currentDOM

An optional reference to an open Fireworks document. If not provided, the LayerTree will default to the current document.

inIgnoreWebLayers Boolean <optional>
false

Pass true to create a LayerTree that does not include any Layer instances for the web layers in the document, which makes looping over the layers a little simpler if you want to ignore slices and hotspots.

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

A LayerTree instance representing the layers in the current document.

Type
Object

Members

currentLayer :Layer

The current Layer of the document. Set this to the index or name of a layer, or to a Layer instance, to set the document's currentLayerNum value.

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

currentTopLayer :Layer

The top-level Layer object that contains the current layer of the document. Set this to the index or name of a layer, or to a Layer instance, to set the document's currentLayerNum value to that layer's top-level ancestor.

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

layers :[Layer]

An array of Layer instances representing all of the layers in the document.

Note that this getter returns a copy of the layers array every time it's accessed, so if you need just one layer, it's a little more efficient to call the layer() method.

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

topLayers :[Layer]

An array of the top Layer instances in the document.

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

webLayer :Layer

A Layer instance representing the top-most web layer.

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

webLayers :[Layer]

An array of the Layer instances representing the web layers in the document.

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

Methods

getContainingLayer

Returns a Layer instance that contains the element.

Note that if you alt-drag an element to a different layer, and then pass that duplicate to this method to find the layer it's on, the wrong one may be returned. That is because when the element is duplicated, both the original and the duplicate share a single customData object, and this method compares customData objects to try to find the element you pass in.

Parameters:
Name Type Description
inElement Object

The element to look for in the current document's layers.

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

A Layer instance that contains the element as an immediate child, or undefined if it can't be found.

Type
Layer

layer

Returns a Layer instance accessed by its index in the layer stack or by its name.

Parameters:
Name Type Description
inIndex Number | String

The 0-based index or name of a layer.

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

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

Type
Layer

refresh

Updates the LayerTree's internal data to reflect the current state of the document and sets any existing Layer instances associated with this tree to a stale state. This method should be called whenever a layer is deleted or rearranged in the stack, which can cause one or more of the layers' indexes to change.

Instead of calling refresh(), you can also just create a new LayerTree instance, which will reflect the current state of the document.

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