Hi,
The code below will produce an array that contains all keyframes of the currently selected layer, represented as timestamps (in string format), determined by the current document's FPS.
In the framesToHMS() function, you can skip the last parameter if you want to get the timestamps as objects.
(function(){
function isKeyFrame( aLayer, frameNum ){
return ( aLayer.frames[ frameNum ].startFrame === frameNum );
}
function framesToHMS( aframes, fps, asAstring ){
var fps = fps || 25;
// Calculate total seconds
var totalSeconds = aframes / fps;
// Calculate hours, minutes, and seconds
var hours = Math.floor( totalSeconds / 3600 );
var minutes = Math.floor( ( totalSeconds % 3600 ) / 60 );
var seconds = Math.floor( totalSeconds % 60 );
// Calculate frames
var frames = aframes % fps;
// Timestamps as string ( Skip the "asAstring" parameter for JSON objects )
return ( asAstring ) ?
( hours + ":" + minutes + ":" + seconds + ":" + frames ) :
{ hours:hours, minutes:minutes, seconds:seconds, frames:frames };
}
function keysToTimeStamps( aLayer, fps ){
var out = [], i;
for( i = 0; i < aLayer.frameCount; i++ ){
if( isKeyFrame( aLayer, i ) ){
out.push( framesToHMS( i, fps, true ) );
}
}
return out;
}
// Example usage ( returns an array of H:M:S:F strings ):
var doc = fl.getDocumentDOM();
var tml = doc.getTimeline();
var selectedLayer = tml.layers[ tml.currentLayer ];
fl.trace( keysToTimeStamps( selectedLayer, doc.frameRate ) );
})();