• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
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

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!

TOPICS
Code , How to , Import and export , Other , Publish package , Timeline

Views

255

Translate

Translate

Report

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 
...

Votes

Translate

Translate
Engaged ,
Oct 16, 2023 Oct 16, 2023

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



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

Votes

Translate

Translate

Report

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

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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