-
Notifications
You must be signed in to change notification settings - Fork 0
/
Previous Cel.jsfl
50 lines (40 loc) · 1.77 KB
/
Previous Cel.jsfl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var fl = flash;
var theDocument = fl.getDocumentDOM();
var theTimeline = theDocument.getTimeline();
var currentLayerIndex = theTimeline.currentLayer;
var currentFrameIndex = theTimeline.currentFrame;
// Find the previous keyframe on the left or the last keyframe on the layer
var prevKeyframeIndex = findPrevKeyframe(currentLayerIndex, currentFrameIndex);
// Move to the previous keyframe if found
if (prevKeyframeIndex !== -1) {
theTimeline.currentFrame = prevKeyframeIndex;
} else {
alert("No previous keyframe found on this layer.");
}
// Function to find the previous keyframe on the left or the last keyframe on the layer
function findPrevKeyframe(layerIndex, startFrame) {
var frames = theTimeline.layers[layerIndex].frames;
// Check if startFrame is out of bounds
if (startFrame < 0 || startFrame >= frames.length) {
return findLastKeyframe(layerIndex); // Find the last keyframe on the layer
}
// Search for the previous keyframe starting from the current frame index
for (var i = startFrame - 1; i >= 0; i--) {
if (frames[i].startFrame === i) {
return i; // Found the previous keyframe
}
}
// If no keyframe found to the left, find the last keyframe on the layer
return findLastKeyframe(layerIndex);
}
// Function to find the last keyframe on the layer
function findLastKeyframe(layerIndex) {
var frames = theTimeline.layers[layerIndex].frames;
// Search backwards from the end of frames array to find the last keyframe
for (var j = frames.length - 1; j >= 0; j--) {
if (frames[j].startFrame === j) {
return j; // Found the last keyframe on the layer
}
}
return -1; // Return -1 if no keyframe found on the layer
}