Skip to main content
Participant
September 12, 2022
Question

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

  • September 12, 2022
  • 2 replies
  • 666 views

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.

    This topic has been closed for replies.

    2 replies

    Participant
    September 13, 2022

    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();

     

    kglad
    Community Expert
    Community Expert
    September 13, 2022

    glad to hear!

    kglad
    Community Expert
    Community Expert
    September 12, 2022

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