2011-11-02 85 views
0

這是illustrator的擴展,它基本上是JavaScript。我想第二個彈出窗口只顯示一次,我試圖告訴它,如果變量已經存在不做,但如果它不要求輸入。任何想法我做錯了什麼?簡單的JavaScript循環

#target illustrator 
if (app.documents.length > 0) { 
    var replaceThis = prompt('What font do you want to replace?','') 
    for (i = 0; i< app.activeDocument.textFrames.length; i++) { //loop through the layers 
     var textArtRange = app.activeDocument.textFrames[i].textRange; 
     var fontSize = textArtRange.characterAttributes.size; 
     //var replaceThis = "10"; 
     //alert("replace this:" + replaceThis); 
     // alert("current font size" + fontSize); 
     if (fontSize == replaceThis) { 
      Replacefont(); 
     } 
     function Replacefont() { 
       //var newSize = "90"; 
       if (!newSize) { 
        var newSize = prompt('Replace '+ replaceThis +'pt with:','') 
       } 
       textArtRange.characterAttributes.size = newSize; 
       alert("yay"); 
     } 
    } 
} 

回答

1
newSize

僅內部ReplaceFont可用,並且每個函數結束時間將被丟棄。你需要使它像這樣持久化(沒有真正的理由做出單獨的功能)。 for循環也不要忘記var

#target illustrator 
if (app.documents.length > 0) { 
    var replaceThis = prompt('What font do you want to replace?',''); 
    var newSize = prompt('Replace '+ replaceThis +'pt with:',''); 

    for (var i = 0; i < app.activeDocument.textFrames.length; i++) { 
     var textArtRange = app.activeDocument.textFrames[i].textRange; 
     var fontSize = textArtRange.characterAttributes.size; 

     if (fontSize == replaceThis) { 
      textArtRange.characterAttributes.size = newSize; 
      alert("yay"); 
     } 
    } 
}