2010-04-24 72 views
6

我有一個閃存.fla編譯爲一個.swc引用圖像,但現在我需要加載所有這些圖像外部,我沒有原始資產。從庫中批量導出圖像?

我知道我可以一個一個地導出它們,但是我有幾百個文件,並且想要找到一個更簡單的方法。

任何幫助都會很棒。

+0

我很困惑。你沒有原始資產? – 2010-09-21 11:23:07

回答

6

你可以使用這個腳本。它僅從您的庫中導出位圖

//created by Heitara 
var folderURI = fl.browseForFolderURL('Select folder where all images should be exported as *.PNG'); 

var doc = fl.getDocumentDOM(); 
var newDoc = fl.createDocument(); 
//fl.outputPanel.trace("Init"); 

if(doc && newDoc) 
{ 
    fl.outputPanel.trace("Start"); 
    var library = doc.library; 
    var allLibItems = library.items; 
    var item; 
    var c = 0; 
    var selectedItemOnStage; 
    var selectionArray; 
    var itemName; 

    for (var i = 0; i<allLibItems.length; ++i) 
    { 
     item = allLibItems[i];//only images will be processed 
     if(item.itemType == "bitmap") //|| item.itemType == "graphic") 
     { 
      // attach image 
      newDoc.addItem({x:0.0, y:0.0}, item); 

      //postition all items on (0,0) 
      var image = newDoc.getTimeline().layers[0].frames[0].elements[0]; 
      if(image) 
      { 

       var hpx = image.hPixels; 
       var vpx = image.vPixels; 

       newDoc.width = hpx; 
       newDoc.height = vpx; 
       // we need to reposition the image, otherwise it will be centered 
       image.x = 0; 

       image.y = 0; 
      } 

      itemName = item.name.split('.')[0]; 
      //export as png 
      newDoc.exportPNG(folderURI + "/"+itemName +".png",true,true); 
      //select all 
      newDoc.selectAll(); 
      //remove selection 
      newDoc.deleteSelection(); 
      //deselect everything 
      newDoc.selectNone(); 
      //output.trace("[END]"); 

     } 

    } 
} 

//close the new document withut saving it 
fl.closeDocument(newDoc, false); 

只需將其保存爲.jsfl文件並從閃存中打開它。 您還應該打開要從中導出所有圖像的.fla文件。

最佳, 埃米爾

附:其他解決方案是將.fla重命名爲.zip(.rar)文件並提取所有資產。這僅適用於使用最新版本的Flash CS5或CS5 +創建的.fla文件。

+0

這仍然適用於CS6。只有改變我必須做的是清理輸出路徑不包括斜線 - 在導出PNG之前轉換itemName,就像這樣做:'itemName.replace(/ \ // g,' - ')。replace (//g,' - ')' – 2015-09-30 05:38:08