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
Branching Function
Moderator: Paul Tuersley
-
- Posts: 704
- Joined: June 5th, 2004, 7:59 am
- Location: London, UK
Well the first thing I noticed is that you don't have a 'var' before your i=1 in your loop through the layers, so there's a fair chance that it's losing your first i's value when you recurse back into the function.
Personally I find recursive functions a bit tricky too, so if you're still having problems it'd be easier to debug if you posted the entire script so I could try it out.
Paul T
Personally I find recursive functions a bit tricky too, so if you're still having problems it'd be easier to debug if you posted the entire script so I could try it out.
Paul T