JSFL:導入根文件夾將全部圖片添加庫連接導出swf

功能:導入文件夾,這個文件夾內的全部png和jpg將按目錄導入到庫中並依據路徑設置爲As連接,最終導出在根目錄一個swf,包含全部的這些圖片和連接。url

 1 //功能:導入圖片根目錄res
 2 
 3 
 4 //clearAllItem();
 5 var folderURL = fl.browseForFolderURL("請選擇game下面的res目錄.");
 6 var rootFolderIdx = folderURL.lastIndexOf("/") + 1;
 7 fl.trace(folderURL);
 8 fl.trace("*******");
 9 var doc = fl.getDocumentDOM();
10 var myPattern = /\//g; 
11 var hasBmp = false;
12 importImage(folderURL, "");
13 if(hasBmp) doc.exportSWF(getSwfName(folderURL));
14 
15 function importImage(fUrl, folderName)
16 {
17     var folderContents = FLfile.listFolder(fUrl);
18     var fName;
19     var item;
20     var i;
21     
22     
23     folderName = getUrlToName(fUrl);
24     
25     for(i=0; i<folderContents.length; i++)
26     {
27         fName = folderContents[i];
28                 
29         //文件夾(若是是子文件夾 D)
30         if(FLfile.getAttributes(fUrl + "/" + fName) == "D")
31         {
32             importImage(fUrl + "/" + fName, folderName+"/");
33         }
34     }
35     //clearAllItem();
36     doc.library.newFolder(folderName);
37     for(i=0; i<folderContents.length; i++)
38     {
39         fName = folderContents[i];
40                 
41         if(fName.indexOf(".png") != -1 || fName.indexOf(".PNG")!= -1 || fName.indexOf(".jpg")!= -1 || fName.indexOf(".JPG")!= -1)
42         {
43             doc.importFile(fUrl + "/" + fName, true);
44             doc.library.moveToFolder(folderName, fName);
45             doc.library.selectItem(folderName+"/" + fName);
46             var items = doc.library.getSelectedItems();
47             item = doc.library.getSelectedItems()[0];
48             item.name = fName;
49             var a = fUrl.substr(rootFolderIdx);
50             a = a.replace(myPattern,"_");
51             var b = fName.substr(0, fName.length-4);
52             setItem(item, a + "_" + b );
53             hasBmp = true;
54         }
55     }
56 }
57 
58 function setItem(item, asName)
59 {
60     fl.trace("導出的連接爲:"+asName);
61     if (item.linkageImportForRS == true) 
62     {
63         item.linkageImportForRS = false;
64     }
65     item.linkageExportForAS = true;
66     item.linkageExportForRS = false;
67     item.linkageExportInFirstFrame = true;
68     item.linkageClassName = asName;
69 }
70 
71 //經過url獲取文件名字
72 function getUrlToName(url)
73 {
74     var index = url.lastIndexOf("/");
75     return url.substr(index+1);
76 }
77 
78 function getSwfName(url)
79 {
80     var swfName = url + "/" + getUrlToName(url) + ".swf";
81     return swfName;
82 }
83 
84 function clearAllItem()
85 {
86     doc.library.selectAll(true);
87     var items = doc.library.getSelectedItems();
88     if(items.length > 0)
89     {
90         var i;
91         for(i=items.length-1; i>-1; i--)
92         {
93             if(items[i].itemType == "bitmap")
94             {
95                 doc.library.deleteItem(items[i].name);
96             }
97         }
98     }
99 }
相關文章
相關標籤/搜索