jsfl 扩展功能(给图片添加AS链接)
//功能:导入图片根目录res
//clearAllItem();
var folderURL =
fl.browseForFolderURL("请选择文件夹.");
var rootFolderIdx =
folderURL.lastIndexOf("/") +
1;
fl.trace(folderURL);
fl.trace("*******");
var doc =
fl.getDocumentDOM();
var myPattern = /\//g;
var hasBmp =
false;
importImage(folderURL, "");
if(hasBmp)
doc.exportSWF(getSwfName(folderURL));
function importImage(fUrl, folderName)
{
var folderContents =
FLfile.listFolder(fUrl);
var fName;
var item;
var
i;
folderName = getUrlToName(fUrl);
for(i=0;
i<folderContents.length; i++)
{
fName =
folderContents[i];
//文件夹(如果是子文件夹 D)
if(FLfile.getAttributes(fUrl + "/" + fName) == "D")
{
importImage(fUrl + "/" + fName, folderName+"/");
}
}
clearAllItem();
doc.library.newFolder(folderName);
for(i=0;
i<folderContents.length; i++)
{
fName =
folderContents[i];
if(fName.indexOf(".png") != -1 ||
fName.indexOf(".PNG")!= -1 || fName.indexOf(".jpg")!= -1 ||
fName.indexOf(".JPG")!= -1)
{
doc.importFile(fUrl +
"/" + fName, true);
doc.library.moveToFolder(folderName,
fName);
doc.library.selectItem(folderName+"/" + fName);
var items = doc.library.getSelectedItems();
item =
doc.library.getSelectedItems()[0];
item.name = fName;
var a = fUrl.substr(rootFolderIdx);
a =
a.replace(myPattern,"_");
var b = fName.substr(0,
fName.length-4);
//setItem(item, a + "_" + b );
setItem(item, b );
hasBmp = true;
}
}
}
function setItem(item, asName)
{
fl.trace("导出的链接为:"+asName);
if (item.linkageImportForRS == true)
{
item.linkageImportForRS = false;
}
item.linkageExportForAS =
true;
item.linkageExportForRS = false;
item.linkageExportInFirstFrame = true;
item.linkageClassName =
asName;
}
//通过url获取文件名字
function getUrlToName(url)
{
var index =
url.lastIndexOf("/");
return url.substr(index+1);
}
function getSwfName(url)
{
var swfName = url + "/" +
getUrlToName(url) + ".swf";
return swfName;
}
function clearAllItem()
{
doc.library.selectAll(true);
var
items = doc.library.getSelectedItems();
if(items.length > 0)
{
var i;
for(i=items.length-1; i>-1; i--)
{
if(items[i].itemType == "bitmap")
{
doc.library.deleteItem(items[i].name);
}
}
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。