Branching Function
Posted: October 27th, 2004, 9:10 am
I'm trying to get a script to work that changes the length of all comps under a selected comp.
The problem is that I have a recursive function to go through all the layers and find the comps. It works fine down one branch of my comp, but if I have two precomps in one comp, it doesn't get to the others.
Example:
Main Comp--Pre Comp 1--SubPre Comp1
------------------------------SubPre Comp2
---------------Pre Comp 2--SubPreComp3
My script would change the length of Pre Comp 1, SubPre Comp1, and SubPre Comp2 but then stop. What is a good way to get my script to back up and try layers further up the chain? Here is my function:
function changeCompDuration(myComp){
//alert('myComp is ' + myComp.name);
var lcoll = myComp.layers;//collection of layer objects in Comp
for (i=1; i<=lcoll.length; ++i){//loop through layers
selItem = lcoll.source;//find layer source in project
if(selItem instanceof CompItem) {//check for comp
var subComp = selItem//set comps to a new variable
selItem.duration = compDur;//set comp length
//alert('subComp is ' + subComp.name + ' It is layer ' + i);
}
lcoll.outPoint = compDur;//set layer out point to comp out point
}
if (subComp != null){
changeCompDuration(subComp);
}
return
The problem is that I have a recursive function to go through all the layers and find the comps. It works fine down one branch of my comp, but if I have two precomps in one comp, it doesn't get to the others.
Example:
Main Comp--Pre Comp 1--SubPre Comp1
------------------------------SubPre Comp2
---------------Pre Comp 2--SubPreComp3
My script would change the length of Pre Comp 1, SubPre Comp1, and SubPre Comp2 but then stop. What is a good way to get my script to back up and try layers further up the chain? Here is my function:
function changeCompDuration(myComp){
//alert('myComp is ' + myComp.name);
var lcoll = myComp.layers;//collection of layer objects in Comp
for (i=1; i<=lcoll.length; ++i){//loop through layers
selItem = lcoll.source;//find layer source in project
if(selItem instanceof CompItem) {//check for comp
var subComp = selItem//set comps to a new variable
selItem.duration = compDur;//set comp length
//alert('subComp is ' + subComp.name + ' It is layer ' + i);
}
lcoll.outPoint = compDur;//set layer out point to comp out point
}
if (subComp != null){
changeCompDuration(subComp);
}
return