Skip to main content
Akenekiart
Participant
October 16, 2023
Answered

Animate JSAPI: Script JSFL which allows you to save javascript code from frames to a text document?

  • October 16, 2023
  • 1 reply
  • 984 views

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!

This topic has been closed for replies.
Correct answer Vladin M. Mitov

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.


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

 

 



1 reply

Vladin M. Mitov
Inspiring
October 16, 2023

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



- Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation
Akenekiart
Participant
October 16, 2023

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?

Vladin M. Mitov
Inspiring
October 16, 2023

Yes, the last line writes everything as "javascript.txt" in the Animate's configuration folder.


- Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation