Can we export from flash to createjs from the comm

2019-06-03 17:51发布

问题:

I am looking for a way to automate the task of running the toolkit for flash for createjs from the command line.

I have a lot of individual components and I would like to export them in a batch process. Can this be done?

回答1:

Your best bet for automation would be to use jsfl. The following script, modified from this thread prompts for a target folder and output folder, then automates the process of opening *.fla files and publishing them via the CreateJS publisher when executed. One caveat is that the CreateJS panel has to be open in Flash already (though there may be a way to do this too).

It is also worth noting that you can just as easily modify this code to either hardcode the path's you need, or read up on the JSFL Docs or dynamically load a manifest file. You can execute them from a batch as well if you really want to run it from a command line.

exporter.jsfl

var folderURI = fl.browseForFolderURL("Please select the folder you want to recurse");
var outputURI = fl.browseForFolderURL("Please select the output path");

var allFlas = FLfile.listFolder(folderURI + "/" + "*.fla", "files");
for(var i = 0; i < allFlas.length; i++)
{
    var flaName = allFlas[i];

    var doc = fl.openDocument(folderURI + "/" + flaName);
    var targetName = doc.name.replace(".fla","");
    var cjsDataKey = "CreateJSToolkit_data";
    //var data = doc.getDataFromDocument(cjsDataKey);
    var data = [
            "version", "0.6",
            "exportHTML", "true",
            "frameBounds", "false",
            "includeHiddenLayers", "false",
            "soundsPath", "sounds/",
            "preview", "false",
            "imagesPath", "images/",
            "libraryPath", "libs/",
            "compactPaths", "false",
            "exportSounds", "true",
            "imagesNS", "images",
            "exportLibs", "true",
            "libNS", "lib_" + targetName.toLowerCase(),
            "hostedLibs", "true",
            "exportImages", "true",
            "outputPath", outputURI,
            "createjsNS", "createjs"
    ];
    doc.addDataToDocument(cjsDataKey, "string", data.join("\n"));
    doc.save();
    doc.close(false);
    // Re-open document so that Publish for CreateJS panel picks up changes.
    doc = fl.openDocument(folderURI + "/" + flaName);
    fl.runScript(fl.configURI + "Commands/Publish for CreateJS.jsfl");
    // Insert an artificial pause here. Seems to be necessary for Toolkit publish.
    alert("Complete!");
    doc.close(false);
}