Copy link to clipboard
Copied
Hi all. I'm trying to create snippet/script that is able to edit the selected layer on the timeline.
More specifically I want to add an instance name to a certain movie clip on the selected layer.
I.e. if the user select a layer and execute the script then it should add the same instance name to each key frame on that layer. Hope it makes sense.
I'm not sure if it is event possible to create something like this.
I'm currently staring to learn ActionScript 3.0, so please excuse me for the dumb question.
Any help or resources/guides will be much appreciated.
Thank you.
Save this script as a command and execute it via "Commands" menu.
(function(){
var myInstanceName = prompt( "Instance name:" );
if( ! myInstanceName ) return;
var tml = fl.getDocumentDOM().getTimeline();
var myLayer = tml.layers[ tml.currentLayer ];
var i, myFrame, j, myElement, myReport = {frameCount:0, elementCount:0};
// Add 'button' to this array if you want to name the button instances as well
var myTypes = [ "movie clip" ];
for( i = 0; i < myLayer.frames.length; i++ ){
...
Copy link to clipboard
Copied
layers don't exist in swf files, so are you asking about jsfl code to edit your fla?
Copy link to clipboard
Copied
Hi @kglad,
Yes, maybe. I'm sorry if my words sound stupid. As I've mentioned I'm still a beginner when it comes to scripting in Animate and I'm trying to understand how everything works.
What I want is to create a script that can edit the fla file by adding an instance name to a certain movie clips.
Could you please refer me to some examples for the Animate's API and/or any examples that manipulates the timeline.
I couldn't find any sufficient information.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thank you very much 🙂
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
Save this script as a command and execute it via "Commands" menu.
(function(){
var myInstanceName = prompt( "Instance name:" );
if( ! myInstanceName ) return;
var tml = fl.getDocumentDOM().getTimeline();
var myLayer = tml.layers[ tml.currentLayer ];
var i, myFrame, j, myElement, myReport = {frameCount:0, elementCount:0};
// Add 'button' to this array if you want to name the button instances as well
var myTypes = [ "movie clip" ];
for( i = 0; i < myLayer.frames.length; i++ ){
myFrame = myLayer.frames[ i ];
// Skip non-keyframes
if( myFrame.startFrame != i ) continue;
myReport.frameCount ++;
for( j = 0; j < myFrame.elements.length; j++ ){
myElement = myFrame.elements[ j ];
if( myTypes.indexOf( myElement.symbolType ) > -1 ){
myElement.name = myInstanceName;
myReport.elementCount ++;
}
}
}
fl.outputPanel.clear();
fl.trace( "Layer: " + myLayer.name );
fl.trace( "Frames: " + myReport.frameCount );
fl.trace( "Instances: " + myReport.elementCount );
})();
Copy link to clipboard
Copied
Thank you very much 🙂
Copy link to clipboard
Copied
Why did you wrap all that up in an IIFE? What does that accomplish in this case?
Copy link to clipboard
Copied
In the finalized code there is no reason for wrapping.
Just to prevent accidental mistakes with variable conflicts or missing definitions while coding and testing - because, all variables, defined in one command script are visible in all other command scripts.