Wednesday, September 15, 2010

JSFL script - iterates over many flas and create swfs for individual symbols


/*
   script tested with Flash CS5,
   should work with older versions.
 */

function universe() {
    var flaPath = "file:///../new_assets/";
    var outputDirPath = "file:///../../../code/trunk/client/game/city/resources/assets/";
    var flaFiles = FLfile.listFolder(flaPath + "*.fla", "files");
    var numFiles = flaFiles.length;
    for (var i = 0; i < numFiles; i++) {
        var flaFilePath = flaPath + flaFiles[i];
        fl.trace("reading "+flaFilePath);
        var doc = fl.openDocument(flaFilePath);
        var items = doc.library.items;
        var iLen = items.length;
        for (var j = 0; j < iLen; j++) {
            var item = items[j];
            if(item.linkageExportForAS) {
                var outputFilePath = outputDirPath+item.linkageClassName+".swf";
                if(fl.fileExists(outputFilePath)) {
                    fl.trace(outputFilePath + " already Exists, you sweet a*s");
                    //return;
                } else {
                    var tmpDoc = fl.createDocument();
                    tmpDoc.addItem({x:0,y:0},item);
                    tmpDoc.exportSWF(outputFilePath);
                    fl.closeDocument(tmpDoc);
                    //fl.trace("exported "+outputFilePath);
                }
            }
        }
        fl.closeDocument(doc);
    }
}
universe();

No comments:

Blog Archive