现在项目需要用到某种格式的swf,既这个swf里的舞台上原点有两个MovieClip,分别命名为mc1,mc2. mc1和mc2都是从外部导入的同一个png图片转为mc而来的。然后导出为这个png同名的swf文件,和png同目录。
代码如下:
//功能:导入图片目录文件夹,输出文件夹内所有图片的swf到这个文件夹。 //用法:新建fla,然后在“命令”》“运行命令”,选择这个jsfl就可。等待几秒钟,就会在刚才选择的文件夹内生成可行的swf。 //@author:Holycy@126.com var folderURI = fl.browseForFolderURL("请选择水玉镜画大图的PNG目录文件夹."); var doc = fl.getDocumentDOM(); importImage(folderURI, "");//在文件夹中导入图片 furl:文件夹在操作系统中的路径; folderName:在库中的路径 function importImage(fUrl, folderName) {var folderContents = FLfile.listFolder(fUrl);var fName;var item;var i;var hasBmp = false;folderName = "bigImg";//处理文件夹for(i=0; i<folderContents.length; i++){fName = folderContents[i];fl.trace("-----------:" + fName + "------------------") ;//文件夹(如果是子文件夹 D)//if(FLfile.getAttributes(fUrl + "/" + fName) == "D")//{// importImage(fUrl + "/" + fName, folderName+"/");//}}clearAllItem();doc.library.newFolder(folderName);//处理图片for(i=0; i<folderContents.length; i++){fName = folderContents[i];if(fName.indexOf(".png") != -1 || fName.indexOf(".PNG")!= -1){doc.importFile(fUrl + "/" + fName, true);doc.library.moveToFolder(folderName, fName);//选择库中的位图doc.library.selectItem(folderName+"/" + fName);var items = doc.library.getSelectedItems();var a = items[0];doc.library.selectItem(folderName+"/" + fName);//放置在舞台的00点doc.library.addItemToDocument({x:0, y:0});//转化为元件doc.convertToSymbol('movie clip', '', 'top left');fl.getDocumentDOM().moveSelectionBy({x:0, y:0});//重复选择一次doc.library.selectItem(folderName+"/" + fName);//放置在舞台的00点doc.library.addItemToDocument({x:0, y:0});//转化为元件doc.convertToSymbol('movie clip', '', 'top left');fl.getDocumentDOM().moveSelectionBy({x:0, y:0});//选择舞台上的对象doc.getTimeline().layers[0].frames[0].elements[0].name = "mc1";doc.getTimeline().layers[0].frames[0].elements[0].x = 0;doc.getTimeline().layers[0].frames[0].elements[0].y = 0;doc.getTimeline().layers[0].frames[0].elements[1].name = "mc2";doc.getTimeline().layers[0].frames[0].elements[1].x = 0;doc.getTimeline().layers[0].frames[0].elements[1].y = 0; //找到刚才选择的文件var fname = a.name;var idx = fname.indexOf(".");var newName = fname.slice(0,idx);fl.trace(fUrl);fl.trace(newName);var index = newName.lastIndexOf("/");newName = newName.substr(index+1);var fullName = fUrl+"/"+String(newName) + ".swf";fl.trace("-----------:" +fullName + "") ;doc.exportSWF(fullName+"");if(i+1<folderContents.length){doc.mouseClick({x:5, y:5}, false, true);doc.deleteSelection();doc.mouseClick({x:5, y:5}, false, true);doc.deleteSelection();}}} }function setItem(item, asName) {if (item.linkageImportForRS == true) {item.linkageImportForRS = false;}item.linkageExportForAS = true;item.linkageExportForRS = false;item.linkageExportInFirstFrame = true;item.linkageClassName = "A" + asName; }function clearAllItem() {doc.library.selectAll(true);var items = doc.library.getSelectedItems();if(items.length > 0){var i;for(i=items.length-1; i>-1; i--){if(items[i].itemType == "bitmap"){doc.library.deleteItem(items[i].name);}}} }