Skip to main content
Known Participant
February 7, 2022
Answered

When executing this jsfl, a JavaScript error occurs

  • February 7, 2022
  • 2 replies
  • 753 views

Achieving the typewriter effect

var doc = fl.getDocumentDOM();

doc.breakApart();
doc.distributeToLayers();
doc.selectAll();


var obs = doc.selection;
doc.getTimeline().insertFrames( obs.length * 2, true, 1); 

var tl = doc.getTimeline();
var total = obs.length;
var i = total + 1;


while( i-- ){
    tl.setSelectedLayers( total - i, true );
    tl.cutFrames(0);
    tl.pasteFrames( i * 2 );
    tl.clearFrames(0, (i * 2));

}
This topic has been closed for replies.
Correct answer kglad

var doc = fl.getDocumentDOM();

doc.breakApart();
doc.distributeToLayers();
doc.selectAll();

var obs = doc.selection;
doc.getTimeline().insertFrames( obs.length * 2, true, 1);

var tl = doc.getTimeline();
var total = obs.length;

for(i=1;i<total;i++){
tl.setSelectedLayers( total - i, true );
tl.cutFrames(0);
tl.pasteFrames( i * 2 );
tl.clearFrames(0, (i * 2));
}

2 replies

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
February 20, 2022

var doc = fl.getDocumentDOM();

doc.breakApart();
doc.distributeToLayers();
doc.selectAll();

var obs = doc.selection;
doc.getTimeline().insertFrames( obs.length * 2, true, 1);

var tl = doc.getTimeline();
var total = obs.length;

for(i=1;i<total;i++){
tl.setSelectedLayers( total - i, true );
tl.cutFrames(0);
tl.pasteFrames( i * 2 );
tl.clearFrames(0, (i * 2));
}

kqskcmAuthor
Known Participant
February 20, 2022

Can the effect in B be achieved?

kglad
Community Expert
Community Expert
February 20, 2022

oops, my error.  use:

 

var doc = fl.getDocumentDOM();

doc.breakApart();
doc.distributeToLayers();
doc.selectAll();

var obs = doc.selection;
doc.getTimeline().insertFrames( obs.length * 2, true, 1);

var tl = doc.getTimeline();
var total = obs.length;

for(i=1;i<=total;i++){
tl.setSelectedLayers( total - i, true );
tl.cutFrames(0);
tl.pasteFrames( i * 2 );
tl.clearFrames(0, (i * 2));
}

 

 

kglad
Community Expert
Community Expert
February 7, 2022
   tl.setSelectedLayers( total - i, true );

 

is going to be out of range when i=0.  ie, don't use while loops unless you really know what you're doing and are certain you're not going to make a mistake.  eg, i never use while loops because i know i make mistakes.

kqskcmAuthor
Known Participant
February 17, 2022

Thanks, is there a good solution

kglad
Community Expert
Community Expert
February 17, 2022

use a for loop.