• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Can I move selected frames from one layer to another using JSFL?

Explorer ,
Sep 11, 2022 Sep 11, 2022

Copy link to clipboard

Copied

Been searching to see and I haven't found anything that could point me in the right direction, so I'm just going to ask outright.  Is it possible to take the currently selected keyframes and create a JSFL script that can move those frames along the timeline?  My current goal is to create a script that can take selected keyframes on the timeline and, if you run this script, it'll move it to the next layer above or below the current selection.  Basically emulating the behavior when you left-click selected keyframes and drag it up or down, essentially, but automating it.  And moving the entire Layer isn't preferred, since I need to change layering later in the timeline and Z sorting the animation doesn't work inside a movieclip.

Views

234

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2022 Sep 12, 2022

Copy link to clipboard

Copied

yes, you can copy, paste and cut frames, so you can move them.  see the jsfl timeline methods.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 12, 2022 Sep 12, 2022

Copy link to clipboard

Copied

Alright, digging and searching more, I think I've created a decent working script.  I'm not great at writing these, but it seems to work in the way that I want it to.  The only thing I think isn't great is it has to create a copy of the frame that needs to move in the next frame, which means the timeline needs to be clean after the current frame so nothing gets messed up.  But I don't anticipate myself having this problem, since I don't want to do this in the middle of an already created animation.

var dom, prefix, timeline, layers, selectedLayers, frame;

function main()
{	
	dom = fl.getDocumentDOM();
	
	if (!dom)
	{
		alert("You need to open a FLA first.");
		return;
	}

	timeline = dom.getTimeline();
	layers = timeline.layers;
	selectedLayers = timeline.getSelectedLayers();
	frame = timeline.currentFrame;
	framenext = timeline.currentFrame+1;

currentlayernum = timeline.currentLayer;
newlayernum = timeline.currentLayer+1;

timeline.copyFrames(frame,frame);
timeline.pasteFrames(framenext,framenext);
timeline.setSelectedLayers(newlayernum);
timeline.copyFrames(frame,frame);
timeline.setSelectedLayers(currentlayernum);
timeline.pasteFrames(frame,frame);
timeline.copyFrames(framenext,framenext);
timeline.clearKeyframes(framenext,framenext);
timeline.setSelectedLayers(newlayernum);
timeline.pasteFrames(frame,frame);

}

main();

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

glad to hear!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

LATEST

Hi,

This example will move the selected frames to the layer below:

(function(){

	function main(){
		
		var doc = fl.getDocumentDOM();

		if ( ! doc ){
			alert( "You need to open a FLA first." );
			return;
		}
		
		var tml = doc.getTimeline(),
			sf = tml.getSelectedFrames(),		// A contiguous one-layer selection in the timeline
			nl = tml.currentLayer + 1,			// Layer below the current one
			newSel = [ nl, sf[1], sf[2] ];		// New timeline selection, based on the existing one
		
		tml.copyFrames();						// Copy frames
		tml.clearKeyframes();					 
		tml.setSelectedFrames( newSel, true );	// Select the same frame span on the new layer
		tml.pasteFrames();						// Paste the copied frames
	}

	main();

})();



- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines