Created
February 27, 2014 12:26
-
-
Save lynxerzhang/9249138 to your computer and use it in GitHub Desktop.
export fla to swf (导出指定目录下的fla文件)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var doc = null; | |
var flaPath = null; | |
var outputPath = null; | |
var recursiveSearch = true; | |
var suffix = "fla"; | |
run(); | |
function run() | |
{ | |
var path = prompt("enter fla's file path", ""); | |
if(!path || path == ""){ | |
return; | |
} | |
flaPath = FLfile.platformPathToURI(path); | |
if(!flaPath || flaPath == ""){ | |
return; | |
} | |
outputPath = flaPath + "/" + "output"; //create a new folder in root directory | |
var isContain = FLfile.exists(outputPath); | |
if(!isContain){ | |
FLfile.createFolder(outputPath); | |
} | |
//recursiveSearch = false; //maybe you don't need recursive search | |
var folderlist = FLfile.listFolder(flaPath); | |
exportFlaFile(folderlist, flaPath); | |
} | |
// | |
function exportFlaFile(folderlist, path) | |
{ | |
if(!folderlist){ | |
return; | |
} | |
//fl.trace(folderlist); | |
var len = folderlist.length; | |
var name = null; | |
var isContain = null; | |
var info = null; | |
var flaPathName = null; | |
for(var i = 0; i < len; i ++){ | |
name = folderlist[i]; | |
if(name){ | |
flaPathName = path + "/" + name; | |
isContain = FLfile.exists(flaPathName); | |
if(isContain){ | |
info = FLfile.getAttributes(flaPathName); | |
if(info == "D"){ | |
//encounter a folder | |
if(recursiveSearch){ | |
exportFlaFile(FLfile.listFolder(flaPathName), flaPathName); | |
} | |
} | |
else{ | |
var isMatch = getType(flaPathName) == suffix; | |
if(isMatch){ | |
fl.trace(flaPathName); | |
fl.openDocument(flaPathName); | |
doc = fl.getDocumentDOM(); | |
//doc.exportSWF(flaPathName, true); | |
doc.exportSWF(outputPath + "/" + getFileName(flaPathName), true); | |
doc.save(false); | |
doc.close(); | |
fl.trace(FLfile.uriToPlatformPath(flaPathName) + " complete export!"); | |
} | |
} | |
} | |
} | |
} | |
} | |
function getFileName(path) | |
{ | |
return path.slice(path.lastIndexOf("/") + 1, path.lastIndexOf(".")); | |
} | |
function getType(path) | |
{ | |
return path.slice(path.lastIndexOf(".") + 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment