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

Edit layer with code

Community Beginner ,
Jun 16, 2022 Jun 16, 2022

Copy link to clipboard

Copied

Hi all. I'm trying to create snippet/script that is able to edit the selected layer on the timeline.
More specifically I want to add an instance name to a certain movie clip on the selected layer.

I.e. if the user select a layer and execute the script then it should add the same instance name to each key frame on that layer. Hope it makes sense.

I'm not sure if it is event possible to create something like this.
I'm currently staring to learn ActionScript 3.0, so please excuse me for the dumb question.
Any help or resources/guides will be much appreciated.
Thank you.

Views

321

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 , Jun 17, 2022 Jun 17, 2022

Save this script as a command and execute it via "Commands" menu.

(function(){
			
	var myInstanceName = prompt( "Instance name:" );
	if( ! myInstanceName ) return;
	

	var tml = fl.getDocumentDOM().getTimeline();
	var myLayer = tml.layers[ tml.currentLayer ];
	var i, myFrame, j, myElement, myReport = {frameCount:0, elementCount:0};

	// Add 'button' to this array if you want to name the button instances as well
	var myTypes = [ "movie clip" ];
	
	
	for( i = 0; i < myLayer.frames.length; i++ ){
	
...

Votes

Translate

Translate
Community Expert ,
Jun 16, 2022 Jun 16, 2022

Copy link to clipboard

Copied

layers don't exist in swf files, so are you asking about jsfl code to edit your fla?

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 ,
Jun 16, 2022 Jun 16, 2022

Copy link to clipboard

Copied

Hi @kglad,

Yes, maybe. I'm sorry if my words sound stupid. As I've mentioned I'm still a beginner when it comes to scripting in Animate and I'm trying to understand how everything works.
What I want is to create a script that can edit the fla file by adding an instance name to a certain movie clips.
Could you please refer me to some examples for the Animate's API and/or any examples that manipulates the timeline.
I couldn't find any sufficient information.

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 Expert ,
Jun 17, 2022 Jun 17, 2022

Copy link to clipboard

Copied

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 ,
Jun 20, 2022 Jun 20, 2022

Copy link to clipboard

Copied

Thank you very much 🙂

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 Expert ,
Jun 20, 2022 Jun 20, 2022

Copy link to clipboard

Copied

you're welcome.

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 ,
Jun 17, 2022 Jun 17, 2022

Copy link to clipboard

Copied

Save this script as a command and execute it via "Commands" menu.

(function(){
			
	var myInstanceName = prompt( "Instance name:" );
	if( ! myInstanceName ) return;
	

	var tml = fl.getDocumentDOM().getTimeline();
	var myLayer = tml.layers[ tml.currentLayer ];
	var i, myFrame, j, myElement, myReport = {frameCount:0, elementCount:0};

	// Add 'button' to this array if you want to name the button instances as well
	var myTypes = [ "movie clip" ];
	
	
	for( i = 0; i < myLayer.frames.length; i++ ){
		myFrame = myLayer.frames[ i ];
		
		// Skip non-keyframes
		if( myFrame.startFrame != i ) continue;
		
		myReport.frameCount ++;
		
		for( j = 0; j < myFrame.elements.length; j++ ){
			
			myElement = myFrame.elements[ j ];
			
			if( myTypes.indexOf( myElement.symbolType ) > -1 ){
				myElement.name = myInstanceName;
				myReport.elementCount ++;
			}
		}
	}
	
	fl.outputPanel.clear();
	fl.trace( "Layer: " + myLayer.name );
	fl.trace( "Frames: " + myReport.frameCount );
	fl.trace( "Instances: " + myReport.elementCount );
})();

 

 

- 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 ,
Jun 20, 2022 Jun 20, 2022

Copy link to clipboard

Copied

Thank you very much 🙂

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
LEGEND ,
Jun 21, 2022 Jun 21, 2022

Copy link to clipboard

Copied

Why did you wrap all that up in an IIFE? What does that accomplish in this case?

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 ,
Jun 21, 2022 Jun 21, 2022

Copy link to clipboard

Copied

LATEST

In the finalized code there is no reason for wrapping.
Just to prevent accidental mistakes with variable conflicts or missing definitions while coding and testing - because, all variables, defined in one command script are visible in all other command scripts.

 

 

- 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