Copy link to clipboard
Copied
Is it possible to add a keyframe to a non selected layer using jsfl? Or does it need to be selected first with setSelectedLayers(index)?
Hi.
If I'm understanding correctly, the currentLayer approach is what you want.
But please notice that selecting a layer and selecting a keyframe are different things.
The code below should select the second layer and create a keyframe at index 5. Then it should reselect the original layer and the original keyframe.
...var doc = fl.getDocumentDOM();
var timeline = doc.getTimeline();
var currentLayer = timeline.currentLayer;
var selectedFrames = timeline.getSelectedFrames();
var targetLayer = 1;
var targetFr
Copy link to clipboard
Copied
Hi,
Both commands - convertToKeyframes() and inserttKeyframe() work on the current layer.
So, you don't need to select the layer, just make it current.
var tml = fl.getDocumentDOM().getTimeline();
tml.currentLayer = 2;
tml.convertToKeyframes();
Copy link to clipboard
Copied
Thanks. But setting the current layer focuses that layer to be selected in the main Animate timeline, whereas we want the current selection to remain and only add a keyframe to another layer, not select it. Here's some code:
var cFrame = tl.currentFrame;
var tml = fl.getDocumentDOM().getTimeline();
tml.currentLayer = 1; //childIndex
tml.convertToKeyframes(cFrame);
fl.getDocumentDOM().getTimeline().currentFrame = cFrame
With layer 3 selected, this adds a keyframe to the correct layer index, 1 but the timeline in Animate shifts and stays selected on layer 1 when it needs to remain on layer 3. If we add tml.currentLayer = 3 after line 04, it still remains on layer 1..
The reason for line 05 is to return the playhead back to the current frame (cFrame) because when you run convertToKeyframes, the playhead ends up moving one forward. The above routine is in a "mouseMove" eventListener so the playhead needs to stay put.
Copy link to clipboard
Copied
kilopop2000 wrote
The above routine is in a "mouseMove" eventListener so the playhead needs to stay put.
You're adding keyframes when the user moves the mouse?!
Copy link to clipboard
Copied
ClayUUID, not quite. The mouse eventListener runs a function that, among other things, checks if a current selected frame is a keyframe and sets it as one if it isn't one already.
Copy link to clipboard
Copied
Hi.
If I'm understanding correctly, the currentLayer approach is what you want.
But please notice that selecting a layer and selecting a keyframe are different things.
The code below should select the second layer and create a keyframe at index 5. Then it should reselect the original layer and the original keyframe.
var doc = fl.getDocumentDOM();
var timeline = doc.getTimeline();
var currentLayer = timeline.currentLayer;
var selectedFrames = timeline.getSelectedFrames();
var targetLayer = 1;
var targetFrame = 5;
timeline.currentLayer = targetLayer;
timeline.convertToKeyframes(targetFrame);
timeline.currentLayer = currentLayer;
timeline.setSelectedFrames(selectedFrames);
Please let us know if this is helpful somehow.
Regards,
JC
Copy link to clipboard
Copied
JoãoCésar Yes, you're right about having to re-select the current frames after converting the target frame to a keyframe. Thanks for taking a look.
Copy link to clipboard
Copied
You're welcome!
Copy link to clipboard
Copied
What if all layers are inside a symbol