Copy link to clipboard
Copied
Same as above in the question. Is there a way or code that will allow me to save the javascript code that is placed on frames on the main timeline to a text document with the ".txt" extension? I saw that there is an option to save things from library like: sounds and images. But is there an option to save all the javascript code? Thank you for your answer!
Here is reworked version, which saves the code in the document's folder:
var doc = fl.getDocumentDOM();
var tml = doc.getTimeline();
var filePath = doc.pathURI.split( "/" ).slice( 0,-1 ).join( "/" ) + "/" + doc.name + "__code.txt";
var i, j, frm, textToSave = "";
for( i = 0; i < tml.layers.length; i++ ){
for( j = 0; j < tml.layers[i].frames.length; j++ ){
frm = tml.layers[ i ].frames[ j ];
if( frm.startFrame === j ){
if( frm.actionScript ){
textToSave += "layer
...
Copy link to clipboard
Copied
Hi,
You need to iterate through the frames you interested in, collect the code (AS or JavaScript) via frame property called 'actionScript' and finally - to save the string. For example:
var tml = fl.getDocumentDOM().getTimeline();
var filePath = fl.configURI + "javascript.txt";
var i, j, frm, textToSave = "";
for( i = 0; i < tml.layers.length; i++ ){
for( j = 0; j < tml.layers[i].frames.length; j++ ){
frm = tml.layers[ i ].frames[ j ];
if( frm.startFrame === j ){
if( frm.actionScript ){
textToSave += "layer " + tml.layers[i].name + ", frame " + j + "\n\n" + frm.actionScript + "\n======================\n\n\n";
}
}
}
}
fl.trace( textToSave )
FLfile.write( filePath, textToSave );
Copy link to clipboard
Copied
That's exactly what I wanted! But would it be possible to save this code in a separate text file? From what I can see, the entire code is called in the internal console "output" in the Adobe animate program. Would it be possible to save all this to a separate text file?
Copy link to clipboard
Copied
Yes, the last line writes everything as "javascript.txt" in the Animate's configuration folder.
Copy link to clipboard
Copied
Where is the .fla file for which I open the script file? If so, it doesn't save to this folder. If I understand correctly.
Copy link to clipboard
Copied
Here is reworked version, which saves the code in the document's folder:
var doc = fl.getDocumentDOM();
var tml = doc.getTimeline();
var filePath = doc.pathURI.split( "/" ).slice( 0,-1 ).join( "/" ) + "/" + doc.name + "__code.txt";
var i, j, frm, textToSave = "";
for( i = 0; i < tml.layers.length; i++ ){
for( j = 0; j < tml.layers[i].frames.length; j++ ){
frm = tml.layers[ i ].frames[ j ];
if( frm.startFrame === j ){
if( frm.actionScript ){
textToSave += "layer " + tml.layers[i].name + ", frame " + j + "\n\n" + frm.actionScript + "\n======================\n\n\n";
}
}
}
}
fl.trace( textToSave );
FLfile.write( filePath, textToSave );