Skip to main content
Participant
Sep 12, 2022 3:32 AM UTC
Question

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

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 is closed to new replies. Start a new post to keep the conversation going.

    4 replies

    Participant
    Sep 13, 2022 12:20 AM UTC

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

     

    Translate
    kglad
    Community Expert
    Community Expert
    Sep 13, 2022 4:47 PM UTC

    glad to hear!

    Translate
    kglad
    Community Expert
    Community Expert
    Sep 12, 2022 1:46 PM UTC

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

    Translate