PDA

View Full Version : Removing Frames b/w Keyframes


Cerulean
08-16-2005, 12:23 AM
Hey there...

I am presently working on a project in which I am creating a custom JSFL file. The functionality I am looking for is that whenever I run the command a blank keyFrame will be inserted into the first frame, shifting all of the other frames over one. Then, I need to remove all of the frames that are between any keyframes so that the FLA is nothing but a series of keyFrames with a blank keyFrame in front.

I have so far gotten the blank keyFrame in and the layers shifted over one but I need a way to dynamically delete the frames in between the keyFrames, since the files that we will be editing will vary in size and setup. I have created an array that captures all of the startFrames and then lists the frameSpan but I am unable, for some reason, to remove them from the timeline. Any suggestions or advise? Here is the jsfl file that I have created so far:

var doc = fl.getDocumentDOM();
var tim = fl.getDocumentDOM().getTimeline();
var frCnt = tim.frameCount;
var lyCnt = tim.layerCount;
//
//
/*
Cut all frames from the timeline so I can
insert a blank key frame in the first frame - jbm
*/
//
tim.selectAllFrames();
tim.cutFrames();
tim.currentLayer = 0;
for (var j=0; j<frCnt; j++) {
tim.selectAllFrames(0,frCnt);
tim.removeFrames(0,frCnt);
tim.currentLayer += 1;
}
//
/*
Create a 'Stop' action for the first frame
Label first frame 'Blank Frame'
Paste Frames at layer index 0 frame index 1 - jbm
*/
//
tim.currentLayer = 0;
tim.addNewLayer();
tim.insertBlankKeyframe(0);
tim.layers[0].frames[0].actionScript = 'stop();';
tim.setFrameProperty('name', 'Blank Frame');
//
//
tim.currentLayer = 0;
tim.pasteFrames(1);
//
var lyCnt02 = tim.layerCount;
var frCnt02 = tim.frameCount;
/*
Rename all layer "New Layer" plus their index number
ie: New Layer 0, New Layer 1, etc... - jbm
*/
//

tim.currentLayer = 0;
for (var i=0; i<lyCnt; i++) {
for (j=0; j<n; j++) {
var curLayer = tim.currentLayer;
var curFrame = tim.currentFrame;
var frameArray = tim.layers[curLayer].frames;
var n = frameArray.length;
var frameSpan = tim.layers[curLayer].frames[curFrame].duration;
var stFrame = frameArray[j].startFrame;
var delFrame01 = stFrame + 1;
var delFrame02 = delFrame01 + 1;
fl.trace(lyCnt02);
if (j==stFrame) {
fl.trace("Keyframe at: " + j);
fl.trace("Duration of " + frameSpan + "frames");
tim.setSelectedFrames(delFrame01);
tim.removeFrames(delFrame01, delFrame02);
}
}
if (lyCnt02>lyCnt) {
for (var k=0; k<lyCnt02; k++) {
var curLayer = tim.currentLayer;
var delLyr = lyCnt;
tim.currentLayer = delLyr;
tim.deleteLayer(delLyr);
}
}
tim.layers[curLayer].locked = true;
tim.currentLayer += 1;
tim.currentFrame += 1;
}