JSFL script to export all pictures in Flash

      JSFL refers to Flash JavaScript, which is a JavaScript script file and an important tool for extending Flash IDE. As an AS3 programmer, it is very important to learn and use JSFL proficiently. After using JSFL, you will be surprised to find that, wow, it turns out that Flash development can be done so efficiently.
      In the as3 development process, editing Fla and using it is an important process, when a Fla is finalized. Mature developers often back up the resources in the finalized version to SVN.  This not only makes a good backup, but also facilitates the direct search in the folder when you want to use a single picture in the future. Since many pictures are often involved in a Fla, if you rely on manpower to export pictures one by one, then classify and save them. It is time-consuming, labor-intensive, and prone to omissions. At this time, we wondered if we could write a script and let the code help us realize this process.

Here is a complete example of JSFL:

var doc = fl.getDocumentDOM(); 
var name = doc.name; 
//设定输出路径为flaout 
var path = "file:///D:/flaout/"; 
//获取fla文件名,并且去除.fla扩展名 
var dir = name.substring(0, name.length-4) 
var items = doc.library.items; 
path = path + dir; 
//在输出路径里创建一个和fla同名的目录 
FLfile.createFolder(path); 
for (i = 0; i < items.length; i++) 
{ 
   if(items[i].itemType == "bitmap") 
    { 
       fl.trace("输出文件=>" + path + "/" +items[i].name); 
       items[i].allowSmoothing = true; 
       items[i].compressionType = "lossless"; 

       //获取当前元件所在目录 
       var subpath = path + "/" + items[i].name; 
       subpath = subpath.substring(0,subpath.lastIndexOf("/")); 
       //创建目录 
       FLfile.createFolder(subpath); 
       //输出文件 
       items[i].exportToFile(path + "/" + items[i].name ); 
    } 
} 
alert("输出完毕,关闭文件,请勿保存"); 
doc.close(); 

The above is the code of a JSFL file, put this code in a notepad and change the suffix name to .jsfl and name it ExportFile.jsfl here
Open a Fla with Adobe Flash CS
Click Commands-->Run Command...
Select ExportFile.jsfl.
Fla is not saved after output (the reason for not saving is because we only export the pictures in Fla, and do not need to modify Fla).
Then you can see all the pictures in this fla in D:/flaout. If necessary, you can also modify the saved path yourself.


Guess you like

Origin blog.csdn.net/gtncwy/article/details/51452794
Recommended