20111125

利用JSFL将FLA文件批量导出为PNG位图

Author:  WinkCategories:  SoftwaresNo Comments »
Tags:  , ,

手里有不少FLA格式的矢量图资源,都不错,只是看起来和用起来挺麻烦的,还要每次都打开Adobe Flash,而且FLA格式预览也是个问题。所以想把它们转换为PNG位图,平常用用够了。不过几百个文件导来导去实在麻烦的紧,而且Adobe Flash又没有Adobe Fireworks那样内置的批处理功能。

好在Adobe Flash强项是JSFL,也就是Flash版本的JavaScript,那么就利用它来简化工作吧。于是写了一段脚本,代码如下,很简单的,先选源文件目录,再选保存目录。扩展名判断和帧判断也没有太细致地去弄,反正是矢量图,就一帧,文件名别有额外的小数点就好。

/**
* Export .png images from fla files in a folder.
* By Wink @ Lynn Studio Documents Network (LSDN).
* Visit www.lynnstudio.net for more information.
*/
var resURI = fl.browseForFolderURL("Select the folder where the FLA files are located");
var outURI = fl.browseForFolderURL("Select the folder where all images should be exported as *.PNG");
var resFiles = FLfile.listFolder(resURI+"/*.fla", "files");
fl.outputPanel.clear();

function convert2png(){
	for(var i = 0;i<resFiles.length;i++) {
		var doc = fl.openDocument(resURI + '/' + resFiles[i]);
		var fileName = document.name.split('.')[0];
		var fileURI = outURI + "/" + fileName + ".png";
		doc.exportPNG(fileURI, true , true);
		doc.close(false);
	}
}
convert2png();

将上面的代码复制并保存为.jsfl文件运行即可,当然也可以直接下载代码包

You can follow any responses to this entry through the RSS 2.0 feed. Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Back to Page Top