Skip to main content
Akenekiart
Participant
Oct 16, 2023 9:13 AM UTC
Answered

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

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 is closed to new replies. Start a new post to keep the conversation going.
Vladin M. Mitov
Vladin M. MitovCorrect answer
Inspiring
Oct 16, 2023 10:41 AM UTC

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

 

 



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

5 replies

Vladin M. Mitov
Inspiring
Oct 16, 2023 9:43 AM UTC

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



Translate
- Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation
Akenekiart
Participant
Oct 16, 2023 10:00 AM UTC

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?

Translate
Vladin M. Mitov
Inspiring
Oct 16, 2023 10:11 AM UTC

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


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