功能:导入文件夹,这个文件夹内的所有png和jpg将按目录导入到库中并依据路径设置为As链接,最终导出在根目录一个swf,包含所有的这些图片和链接。
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 }