-
ExtendScript: Replacing a layer via a function using a != “else” statement.
Hello,
I have a simple GUI with a “edittext” box and an apply button that I use to trigger functions.
I have an instance where I run a for loop to look for the name of a specific composition, so in this case, if I type “player one headshot” into the edittext box, the layer in my comp will be replaced by the “player one headshot” comp in my project window.
What I need is an “else” statement that says “if the user text in the edit text box doesn’t = any compositions with that name, then replace the layer with a comp named “default composition””
How would I do this?
Here’s my working code before the else statement. Feel free to tear this apart as well if there’s a better way to do it:
function checkPlayerHeadshot(){
for (var i = 1; i <= app.project.numItems; i++){
if (app.project.item(i).name == "player one headshot"){
playerNameText = app.project.item(i);
playerHeadshot.replaceSource((playerNameText), true);
break;
}
}
}Best,
Andy.