关闭

使用jsfl批量生成fla文件(文件是在多个文件夹下)如果是单个文件夹下也可以

550人阅读 评论(0) 收藏 举报

最近项目中使用到很多资源需要使用swf格式,但是资源太多,就想到了jsfl,这个家伙太厉害了,有了他工作量就大大减少了,晒下代码分享给大家,写的比较乱,注释也不全,大家如果需要即时交流哦

fl.outputPanel.clear();

var resourcePath=fl.browseForFolderURL("请选择素材路径:");
var swfPath=fl.browseForFolderURL("请选择生成swf文件的路径:");

var bitmapFolder="图素";
var mcFolder="导出类";
analyseFolder(resourcePath,"");

var childName = "";
var flag = false;
//递归处理每个文件夹
function analyseFolder(folderPath,libFolder)
{
var dom = fl.createDocument();
var lib=dom.library;
//fl.trace("libFolder"+libFolder);

if(libFolder == ""){
   childName = "";
}else{
   childName = childName+"_";
}
//fl.trace("childName"+childName);
        var fileList=FLfile.listFolder(folderPath,"files");
        for(var i=0;i<fileList.length;i++)
        {
     //如果元素是位图,则设置其压缩属性
     //fl.trace(lib.getItemType(fileList[i]));
    
   
  
                var fileName=fileList[i];
                var ind=fileName.indexOf(".");
                //如果没有后缀或后缀不正确则略过
                if(ind<=0||ind==(fileName.length-1))
                {
                        continue;
                }
   fl.trace("fileName:::::::"+folderPath+fileName);
                //后缀
                var ext=fileName.substr(ind+1,fileName.length-ind);
                ext=ext.toLowerCase();
                //不是图片则略过
                if(ext!="bmp"&&ext!="gif"&&ext!="jpg"&&ext!="jpeg"&&ext!="png")
                {
                        continue;
                }
    
    
                //不要后缀的文件名
                shortName=fileName.substr(0,ind);
  
  

                var filePath=folderPath+"/"+fileName;
    
                //fl.trace(filePath);
                //导入图片
                dom.importFile(filePath,true);
                //选择项
                lib.selectItem(fileName);
     if(lib.getItemType()=="bitmap"){
      //使用photo(JPEG)压缩
      lib.compressionType="photo";
      lib.quality = 65;
     
      //使用文档的压缩质量,可在导出时设置
      lib.useImportedJPEGQulity=true;
      //fl.trace("aaaaaa"+lib.getItemType());
     }
     //fl.trace(lib.getItemType());
                //放到舞台上
                lib.addItemToDocument({x:0,y:0});
                dom.selectAll();
                dom.convertToSymbol("movie clip",shortName,"top left");
                lib.selectItem(shortName);
                lib.setItemProperty("linkageImportForRS",false);
                lib.setItemProperty("linkageExportForAS",true);
                lib.setItemProperty("linkageExportForRS",false);
                lib.setItemProperty("linkageExportInFirstFrame",true);
                lib.setItemProperty("linkageIdentifier",shortName);
     //fl.trace("shortName        "+shortName);
                dom.selectAll();
                dom.deleteSelection();
                var f=libFolder;
                lib.newFolder(bitmapFolder+f);
                lib.newFolder(mcFolder+f);
                lib.moveToFolder(bitmapFolder+f,fileName);
                lib.moveToFolder(mcFolder+f,shortName);
     fl.trace("flag::::"+flag);
     flag = true;
     //fl.trace("fileName:::::::"+folderPath+fileName);
     fl.trace("转化为元件结束");
     fl.trace("---------------------------");
     dom.exportSWF(swfPath+"/"+shortName+".swf",true);
     fl.saveDocument(dom,swfPath+"/"+shortName+".fla");
     dom.close(false);
     //fl.colse(false);
        }       
        //子文件夹
        var folderList=FLfile.listFolder(folderPath,"directories");
        for(var j=0;j<folderList.length;j++)
        {
   //childName = folderList[j]+"_";
     childName = folderList[j];
     flag = false;
                analyseFolder(folderPath+"/"+folderList[j],libFolder+"/"+folderList[j]);
        }
}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:546572次
    • 积分:7148
    • 等级:
    • 排名:第3244名
    • 原创:71篇
    • 转载:734篇
    • 译文:0篇
    • 评论:11条
    文章分类
    最新评论