zoukankan      html  css  js  c++  java
  • JSFL:导入根文件夹将所有图片添加库链接导出swf

    功能:导入文件夹,这个文件夹内的所有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 }
    关注我: weibo.com/holycy
  • 相关阅读:
    浅谈 PHP 与手机 APP 开发(API 接口开发)
    Thinkphp+Nginx(PHPstudy)下报的404错误,403错误解决
    win7彻底卸载iis
    Java ByteCode 规格严格
    CPUID 规格严格
    Your First Plugin(转载) 规格严格
    SQLYog Enterprise注册码 规格严格
    WSUS API&&WUAPI 规格严格
    linux学习一则 规格严格
    Eclipse分析源代码时总是显示org.eclipse.core.runtime.CoreException错误,找不到***文件(转载) 规格严格
  • 原文地址:https://www.cnblogs.com/holycy/p/3473506.html
Copyright © 2011-2022 走看看