Highlighted

jsfl Add keyframe to non selected layer

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

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

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

TOPICS
Discussions

Views

589

Likes

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

jsfl Add keyframe to non selected layer

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

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

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

TOPICS
Discussions

Views

590

Likes

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
Aug 18, 2019 0
Participant ,
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

Likes

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
Reply
Loading...
Aug 18, 2019 1
Explorer ,
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.

Likes

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
Reply
Loading...
Aug 19, 2019 0
Adobe Community Professional ,
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?!

Likes

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
Reply
Loading...
Aug 19, 2019 0
Explorer ,
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.

Likes

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
Reply
Loading...
Aug 20, 2019 0
Adobe Community Professional ,
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

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Aug 19, 2019 1
Explorer ,
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.

Likes

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
Reply
Loading...
Aug 19, 2019 1
Adobe Community Professional ,
Aug 19, 2019

Copy link to clipboard

Copied

You're welcome!

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Aug 19, 2019 1