Copy link to clipboard
Copied
I'm stuck with trying to select a layer by name.
I must be missing something super basic but I can't figure it out.
var dom = fl.getDocumentDOM();
var timeline = dom.getTimeline();
var targetLayer = timeline.findLayerIndex('Keys')
if (targetLayer !== undefined) {
fl.trace(targetLayer)
timeline.currentLayer = targetLayer;}
// If the target layer is not found, create a new layer and select it
else {
timeline.addNewLayer('Keys');}
The fl.trace(targetLayer) returns a number (7), but the selected layer doesn't change. I also tried setSelectedLayers with the same result.
timeline.setSelectedLayers(targetLayer);
If I put a plain number in place of targetLayer it selects that layer no problem. Is this a bug or is there a work around?
targetLayer (if it's defined) is an array. ie, if you use unique layer names, try:
timeline.setSelectedLayers(targetLayer[0]);
Copy link to clipboard
Copied
targetLayer (if it's defined) is an array. ie, if you use unique layer names, try:
timeline.setSelectedLayers(targetLayer[0]);
Copy link to clipboard
Copied
That makes sense, thank you!
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
Hi.
Please try this:
var tl = fl.getDocumentDOM().getTimeline();
var layerIndex = tl.findLayerIndex("Keys");
tl.setSelectedLayers(layerIndex[0]);
Regards,
JC