Skip to main content
Firewood:D
Inspiring
May 19, 2023 1:55 PM UTC
Answered

How does determine whether the current frame is a Keyframe?

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 is closed to new replies. Start a new post to keep the conversation going.
kglad
kgladCorrect answer
Community Expert
May 19, 2023 2:17 PM UTC

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
}

3 replies

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 19, 2023 2:17 PM UTC

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
}

Translate
Firewood:D
Inspiring
May 20, 2023 4:48 AM UTC

Perfect problem-solving! Thank you.

Translate
kglad
Community Expert
Community Expert
May 20, 2023 4:50 AM UTC

you're welcome.

Translate