Repositioning everything on the stage (across all frames) with JSFL?

I have a bunch of old FLAs with one set of dimensions, including a 60 pixel offset along the y axis. I’m writing a jsfl script to resize the stage (works), delete some unneeded layers (works), and reposition everything (doesn’t work) :frowning:

What I’m using is:

fl.getDocumentDOM().selectAll();
fl.getDocumentDOM().moveSelectionBy({x:46, y:-60});

When I run my script, the items do in fact get moved, but on tweened clips, they get “doubled dipped,” it seems: if I compare the new x and y values of, say, the end keyframe of a clip (only tweened for alpha, for example) is exactly 46 pixels farther right and 60 pixels higher up than it should be.

Is there a better way to reposition everything that avoids this “double dipping” among tweens? I’d love to know! There’s got to be a way, and I feel like I’m so close, but not quite there. (Of course, I’m probably way off…)

Thanks for any advice!

Edit: I’ve performed the steps manually by turning onionskinning on for multiple frames, selecting all frames, then dragging a selection rectangle across everything on the stage, then moving everything by the desired amount, which works: when I look at the history and view the js for those steps, they look exactly like what I’ve typed into my script. The only difference is it works like it should in the IDE; it poops its pants in my script… So sad.

Your solution was close if you had added selectAllFrames and made sure( manualy) thatedit multiple frames was enabled you would have had a solution,

The most reliable solution seems to be finding the keyframes and iterating over every element. (also this method does not require user intervention wich is what I need since this will be dealing with 100s of files)

//Author: Lloyd Franklin Smith smith-dev.net
moveStageContents(100,50);
function moveStageContents(xDistance, yDistance) {

this.isKeyFrame = function(timeline, layerNum, frameNum) {
    if (!timeline.layers[layerNum].frames[frameNum]) {
        return false;
    }
    return (timeline.layers[layerNum].frames[frameNum].startFrame === frameNum);
};

this.moveElements=function(elements) {
    elements.forEach(function(element) {
        element.x = element.x + xDistance;
        element.y = element.y + yDistance;
    });
}

this.moveTimelineContents = function (timeline) {
	var totalMovedElements = 0;
    for (var i = 0; i < timeline.layers.length; i++) {
        for (var j = 0; j < timeline.layers[i].frames.length; j++) {
            if (this.isKeyFrame(timeline, i, j)) {
                moveElements(timeline.layers[i].frames[j].elements);
				totalMovedElements += timeline.layers[i].frames[j].elements.length;

            }
        }

    }
return totalMovedElements;
}

var totalElementsOnAllTimelines = 0;
an.getDocumentDOM().timelines.forEach(function(tml) {
    totalElementsOnAllTimelines += moveTimelineContents(tml);
});
an.trace('Finished moving '+totalElementsOnAllTimelines+' elements');
}
1 Like

image