• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

jsfl Add keyframe to non selected layer

Explorer ,
Aug 18, 2019 Aug 18, 2019

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)?

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 19, 2019 Aug 19, 2019

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

...

Votes

Translate

Translate
Engaged ,
Aug 18, 2019 Aug 18, 2019

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();

- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 19, 2019 Aug 19, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 19, 2019 Aug 19, 2019

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?!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 20, 2019 Aug 20, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 19, 2019 Aug 19, 2019

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 19, 2019 Aug 19, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 19, 2019 Aug 19, 2019

Copy link to clipboard

Copied

You're welcome!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

LATEST

What if all layers are inside a symbol

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines