簡體   English   中英

JSFL將圖像替換為庫圖像

[英]JSFL Replace image for library image

我正在嘗試使用JSFL編寫腳本,但存在以下問題...

要了解Im想要做什么,首先我使用腳本導出庫中的所有圖像,因為我需要對所有PNG文件進行處理。

現在,我想將圖像重新插入庫中。

如果我創建一個新項目,那么我將丟失所有引用,這將是無用的,並且我已復制了項目。

我需要做的是重新導入每個項目的圖像。 我的意思是,與右鍵單擊庫項目->屬性->導入...時的操作相同。

我試圖使用此腳本,但是它不起作用。 有人可以幫助我嗎?

var folderURI = fl.browseForFolderURL('Select folder where all images should be exported as *.PNG');
var doc = fl.getDocumentDOM();

if(doc)
{
    fl.outputPanel.trace("Start");
    var library = doc.library;
    var allLibItems = library.items;
    var item;
    var itemName;

    for (var i = 0; i<allLibItems.length; ++i) 
    {
        item = allLibItems[i];//only images will be processed
        if(item.itemType == "bitmap")
        {
            itemName = item.name.slice(item.name.lastIndexOf("/")+1,item.name.lastIndexOf("."));
            //Find proccesed image on the directory selected before
            //and replace the sourceFilePath (I think this is what I need to use a new image but is not working)
            item.sourceFilePath = folderURI + "/" + itemName +".png"

            //This returns 'false'
            fl.outputPanel.trace(library.updateItem(item.name));
            //item.sourceFilePath has the old value, I don't understand why it was not changed
            fl.outputPanel.trace(folderURI + "/" + itemName +".png" + " = " + item.sourceFilePath);
        }

    }
}

最后,我解壓縮了FLA文件,就像一個zip文件一樣,並且里面有所有圖像,因此替換它們很容易。

我首先遇到的問題是圖像沒有更改,因為在Flash中您可以選擇在創建swf時壓縮圖像,這就是為什么我看不到最終結果的任何變化的原因。 (右鍵單擊庫中的圖像->屬性->壓縮)

我使用JSFL迭代所有圖像(如上面的示例),並設置Compression:“ Lossless”而不是“ Photo(JPG)”。

顯然,這對我來說只是一個不錯的解決方案,因為Im使用外部工具以非常高分辨率和小尺寸壓縮圖像。

您可以使用JSFL迭代所有圖像,並為所有圖像設置Compression:“ Photo(JPG)”,並具有所需的質量,但是結果可能會有所不同。

問候

嘗試這個

  doc.importFile(currentFileURI, true, false, false);
  doc.library.selectItem(currentFileName);
  doc.library.moveToFolder(libraryPath, currentFileName, true);

但是如果項目存在,FLASH將顯示警告對話框

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM