Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Oct 16, 2023 Oct 16, 2023

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!

TOPICS
Code , How to , Import and export , Other , Publish package , Timeline
699
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Oct 16, 2023 Oct 16, 2023

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 
...
Translate
Engaged ,
Oct 16, 2023 Oct 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 1998
Member of Flanimate Power Tools team - extensions for character animation
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 16, 2023 Oct 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 16, 2023 Oct 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 1998
Member of Flanimate Power Tools team - extensions for character animation
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 16, 2023 Oct 16, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 16, 2023 Oct 16, 2023
LATEST

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 1998
Member of Flanimate Power Tools team - extensions for character animation
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines