How to implement multiple symbols random loop playback?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Currently only zoom effects can be done at the same time
Copy link to clipboard
Copied
Hi.
Do you want to pre-randomize the animations before publish (authortime) or after publish (runtime)?
Regards,
JC
Copy link to clipboard
Copied
before publish,Play the effect on the timeline
Copy link to clipboard
Copied
May require jsfl implementation
Copy link to clipboard
Copied
As far as I can tell there's no way to randomize the instances and their properties in each playback.
The only solution I can think of is to randomize some instances and properties in each keyframe.
My suggestion here is to run one script to spawn and randomize the instances and another one to randomize their properties in each keyframe.
Here is a video demonstration:
Spawn Symbol Randomly.jsfl
var dom = fl.getDocumentDOM();
var lib = dom.library;
var timeline = dom.getTimeline();
var symbolName = "Circle";
var total = 16;
var minX = 0;
var maxX = dom.width;
var minY = 0;
var maxY = dom.height;
var minScale = 0.1;
var maxScale = 1;
var minRotation = 0;
var maxRotation = 360;
var minAlpha = 20;
var maxAlpha = 100;
function main()
{
if (!checkForErrors())
{
getUserInput();
randomSpawn();
}
}
function checkForErrors()
{
var currentLayer = timeline.layers[timeline.currentLayer];
var selectedFrames = timeline.getSelectedFrames();
if (!dom)
{
alert("Please open up a FLA first.");
return true;
}
if (currentLayer.layerType === "folder")
{
alert("The current layer is a folder.");
return true;
}
if (currentLayer.locked)
{
alert("The current layer is locked.");
return true;
}
if (selectedFrames.length === 0)
{
alert("There's no selected frame.");
return true;
}
if (selectedFrames[2] > currentLayer.frames.length)
{
alert("Selected frame is null.");
return true;
}
return false;
}
function getUserInput()
{
var userInput, totalInput;
var data = prompt("Please input the Symbol name and the number of instances. E.g.: 'Circle,32.' or 'anims/Player,10.'");
if (data)
{
userInput = data.split(",");
if (userInput.length > 1)
{
totalInput = parseInt(userInput[1]);
symbolName = userInput[0];
total = isNaN(totalInput) ? total : totalInput;
}
}
}
function randomSpawn()
{
var i, randomScale, randomRotation;
for (i = 0; i < total; i++)
{
lib.addItemToDocument({ x: randomRange(minX, maxX), y: randomRange(minY, maxY) }, symbolName);
randomScale = randomRange(minScale, maxScale);
dom.transformSelection(randomScale, 0, 0, randomScale);
dom.rotateSelection(randomRange(minRotation, maxRotation));
dom.setInstanceAlpha(randomRange(minAlpha, maxAlpha));
}
}
function randomRange(min, max)
{
return min + Math.random() * (max - min);
}
fl.outputPanel.clear();
main();
Randomize Instances.jsfl
var dom = fl.getDocumentDOM();
var lib = dom.library;
var timeline = dom.getTimeline();
var minOffsetX = -50;
var maxOffsetX = 50;
var minOffsetY = -30;
var maxOffsetY = 30;
var minOffsetScale = 0.02;
var maxOffsetScale = 0.02;
var minOffsetRotation = 30;
var maxOffsetRotation = 80;
var minAlpha = 20;
var maxAlpha = 100;
function main()
{
if (!checkForErrors())
randomize();
}
function checkForErrors()
{
if (!dom)
{
alert("Please open up a FLA first.");
return true;
}
if (dom.selection.length === 0)
{
alert("There's no instance selected.");
return true;
}
return false;
}
function randomize()
{
var selection = dom.selection;
var total = selection.length;
var element;
dom.selectNone();
for (i = 0; i < total; i++)
{
element = selection[i];
element.selected = true;
element.x += randomRange(minOffsetX, maxOffsetX);
element.y += randomRange(minOffsetY, maxOffsetY);
element.rotation += randomRange(minOffsetRotation, maxOffsetRotation);
element.scaleX += randomRange(minOffsetScale, maxOffsetScale);
element.scaleY = element.scaleX;
dom.setInstanceAlpha(randomRange(minAlpha, maxAlpha));
dom.selectNone();
}
for (i = 0; i < total; i++)
{
element = selection[i];
element.selected = true;
}
}
function randomRange(min, max)
{
return min + Math.random() * (max - min);
}
fl.outputPanel.clear();
main();
Here is the source code / files / JSFL:
I hope it helps.
Regards,
JC
Copy link to clipboard
Copied
Thank you very much for your answer, but you may have misunderstood me。I hope to select many symbols at the same time, execute jsfl, so that the starting frame of each symbol playback is different, so as to realize irregular playback。
Copy link to clipboard
Copied

