Skip to main content
Firewood:D
Inspiring
May 19, 2023
Answered

How does determine whether the current frame is a Keyframe?

  • May 19, 2023
  • 1 reply
  • 764 views

I wrote a simple command that needed to use an if statement to determine the condition. I checked the manual, but I couldn't find an example of judging keyframes.
The ideas are as follows:

 

//Select the current frame.
//Condition judgment:
if (if the current frame equals a Keyframe) {
//execute Command 1
} else {
//if the current frame is not a Keyframe, add a Keyframe and execute command 2
}

The stupid code I wrote can run, but will make an error in the first frame of the layer.
thank you very much!!

 

This topic has been closed for replies.
Correct answer kglad

var doc = fl.getDocumentDOM();
var tl = doc.getTimeline();
//Select the current frame
var c = tl.currentFrame;

// should error check that only one layer is selected
if(c== tl.layers[tl.getSelectedLayers()[0]].frames[c].startFrame){
// do whatever
}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 19, 2023

var doc = fl.getDocumentDOM();
var tl = doc.getTimeline();
//Select the current frame
var c = tl.currentFrame;

// should error check that only one layer is selected
if(c== tl.layers[tl.getSelectedLayers()[0]].frames[c].startFrame){
// do whatever
}

Firewood:D
Inspiring
May 20, 2023

Perfect problem-solving! Thank you.

kglad
Community Expert
Community Expert
May 20, 2023

you're welcome.