Skip to main content
Chaint
Known Participant
April 4, 2023
Answered

Add keyframes for multiple selected frames and adjust symbol transparency to 0

  • April 4, 2023
  • 2 replies
  • 685 views
an.getDocumentDOM().getTimeline().convertToKeyframes();
an.getDocumentDOM().setInstanceAlpha(0);

The above code does not seem to be able to complete the requirements

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

Yes, @kglad  is correct, you need to have a selection in order to execute setInstanceAlpha().
Immediately after executing convertToKeyframes(), there is no valid selection because we are in brand new keyframes. You can check this by using:

an.getDocumentDOM().getTimeline().convertToKeyframes();
an.trace( "selection: " + an.getDocumentDOM().selection );

Therefore, after creating the keyframes, select all elements within them.
Something like this:

var doc = fl.getDocumentDOM();
var tml = doc.getTimeline();
var frameSel = tml.getSelectedFrames();
tml.convertToKeyframes();

doc.selectNone();
for( var i = 0; i < frameSel.length; i+=3 ){
	var xlayer = tml.layers[ frameSel[i] ];
	var frm = xlayer.frames[ frameSel[i+1] ];
	if( ! frm ) continue;
	for( var j = 0; j < frm.elements.length; j++ ){
		frm.elements[j].selected = true;
	}
}
doc.setInstanceAlpha(0);

 

 

2 replies

Vladin M. Mitov
Vladin M. MitovCorrect answer
Inspiring
April 4, 2023

Yes, @kglad  is correct, you need to have a selection in order to execute setInstanceAlpha().
Immediately after executing convertToKeyframes(), there is no valid selection because we are in brand new keyframes. You can check this by using:

an.getDocumentDOM().getTimeline().convertToKeyframes();
an.trace( "selection: " + an.getDocumentDOM().selection );

Therefore, after creating the keyframes, select all elements within them.
Something like this:

var doc = fl.getDocumentDOM();
var tml = doc.getTimeline();
var frameSel = tml.getSelectedFrames();
tml.convertToKeyframes();

doc.selectNone();
for( var i = 0; i < frameSel.length; i+=3 ){
	var xlayer = tml.layers[ frameSel[i] ];
	var frm = xlayer.frames[ frameSel[i+1] ];
	if( ! frm ) continue;
	for( var j = 0; j < frm.elements.length; j++ ){
		frm.elements[j].selected = true;
	}
}
doc.setInstanceAlpha(0);

 

 

- Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation
Vladin M. Mitov
Inspiring
April 4, 2023

If you describe in a little more detail what exactly you want to do, perhaps we can give you some meaningful advice.

 

 

- Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation
Chaint
ChaintAuthor
Known Participant
April 4, 2023

I would like to use a command to automatically add keyframes with 0 transparency for multiple frames