Skip to content

Instantly share code, notes, and snippets.

@AIRIA AIRIA/JSFL
Created Jul 10, 2013

Embed
What would you like to do?
从FlashCS的库面板中 导出指定类型的元素
var dom= fl.getDocumentDOM();
var lib = dom.library;
var items = lib.items;
var saveDir;
var counter = 0;
var dialog = dom.xmlPanel(fl.configURI+"Commands/GiantOS/select.xml");
/* 遍历一个对象的属性 并打印到输出面板 */
function enumProp(obj){
fl.outputPanel.clear();
for(var prop in obj){
fl.trace("property:"+prop+" value:"+obj[prop]);
}
}
/* 获取对象的具体名字 移除文件夹的名字 */
function getItemName(item){
var name = item.name;
var level = name.split("/");
name = level[level.length-1];
level.pop();
var obj = {
name:name,
path:level.join("/")
}
return obj;
}
/* 选择保存的目录 */
function selectSaveDir(){
return fl.browseForFolderURL("选择导出资源存放的目录");
}
/* 导出图片到指定的目录 */
function exportItem(item){
var itemInfo = getItemName(item);
var targetDir = saveDir+"/"+itemInfo.path;
if(!FLfile.exists(targetDir)){
FLfile.createFolder(targetDir);
}
if(item.itemType=="bitmap"){
item.exportToFile(saveDir+"/"+item.name);
}else if(item.itemType == "movie clip"){
item.exportSWF(saveDir+"/"+item.name+".swf");
}
}
if(dialog.dismiss == "accept"){
fl.outputPanel.clear();
saveDir = selectSaveDir();
if(saveDir){
var itemLength = items.length;
var item;
for(var i=0;i<itemLength;i++){
item = items[i];
if(item.itemType == dialog.type){
counter++;
exportItem(item);
}
}
fl.trace("资源导出完毕 总共"+counter+"项");
fl.trace("存放目录:"+FLfile.uriToPlatformPath(saveDir));
}
}
<dialog title="选择导出的库元件类型" buttons="accept,cancel">
<grid>
<columns>
<column />
<column />
</columns>
<rows>
<row align="right">
<label value="元件类型" />
<radiogroup id="type" groupbox="true">
<radio label="影片剪辑" value="movie clip" />
<radio label="图片" value="bitmap"/>
<radio label="声音" value="sound" />
</radiogroup>
</row>
</rows>
</grid>
</dialog>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.