try it like this:
function getItem(theName){
for (var i =1; i <= app.project.numItems; i++){
if ((app.project.item(i)) && (app.project.item(i).name == theName)){
return app.project.item(i);
}
}
return null;
}
function findComp(theName){
for (var i =1; i <= app.project.numItems; i++){
if ((app.project.item(i) instanceof CompItem) && (app.project.item(i).name == theName)){
return app.project.item(i);
}
}
return null;
}
function replaceFile(){
var compName = "mycomp";
var myComp = findComp(compName);
if (myComp == null){
alert("Can't find comp '" + compName + "'.");
return;
}
var myLayer = myComp.layer('pink.png');
var itemName = "blue.png";
var myItem = getItem(itemName);
if (myItem == null){
alert("Can't find item '" + itemName + "'.");
return;
}
myLayer.replaceSource(myItem,false);
}
replaceFile();
Also, if you post code in this forum, please don’t preview your post. It messes things up.
Dan