我试图检查图层类型以确保我的函数调用仅适用于所选图层中的文本图层(所选图层的数量是几百个)。看来我在使用typeOf方法时遇到了一些错误。有人可以帮忙吗?
var myComp = app.project.activeItem;
var selectedLayers = myComp.selectedLayers;
var numLayers = selectedLayers.length;
for(var i=0; i < numLayers; i++){
var mySourceText = selectedLayers[i].property("ADBE Text Properties").property("ADBE Text Document");
var myTextDoc = mySourceText.value;
if (typeOf(selectedLayers[i]) == "TextLayer") {
mySourceText.setValue(trim(myTextDoc));
}
}
function trim(strValue){
var str = new String(strValue);
return str.replace(/(^\s*)|(\s*$)/g,"");
}
你想要的正确布尔测试是
if (selectedLayers[i] instanceof TextLayer) {
instanceof
,没有引用TextLayer
。