How to batch convert flash files to html5?

I am back, well I know no one’s watching here, I paused studying android dev, for some reason.
Yesterday, one of my old buddies called me, regarding for a question.

How to batch convert flash files to html5?

For less than 10 files, you can just simply visit here
Upload your swf file and convert it by its online tools.

For hundred or even thousand fla file to convert, you need do some script things to make it automatically.
Requirements:

  • Flash Professional (Between CS4 and C6), the versions after CC removed the support to ActionScript 2, but the problem is tons of old fla files are written by AS2, that is why we need to convert them.
  • Swiffy Extension, download here 
  • Adobe Extension Manager CS6, we need it to install the extension file.
    Steps:

1. Download Swiffy Extension.

2. mxp to zxp:

You might found that it’s a mxp file, and you can’t install it with new Extension Manager CC. Don’t worry, all you need to do is to convert it to a newer version zxp file with Adobe Extension Manager CS6. After convert it to a zxp file, doubleclick it to install it.

3. Export a single fla to html:

![](https://archive.writeitdown.site/屏幕快照 2015-01-28 下午4.30.16.png)
Open your fla file, click Command Menu on the top, you’ll see “Export as HTML5(Swiffy)”, then wait. If the file doesn’t content any error, a html document will be opened in the browser. Here you might meet some problems.

  • If you found batch of compile errors, check your file’s publish setting, make sure it target and player pointing to a correct option.
    ![](https://archive.writeitdown.site/屏幕快照 2015-01-28 下午4.39.51.png)

  • If you receive an error “TypeError:Swiffy.Compile”, it means your Swiffy extension didn’t initialize properly. It happened to me when I try to use it on Flash CC. Try to use a older version Flash.

  • If you saw an output info like this: “The Swiffy webservice could not be reached. Please check your internet connection.” I think this extension depends on a backend server, and the server is probably in U.S. So don’t forget to turn on your vpn or something else to make sure the network is reachable。
    4. Now we can make it work automaticlly by a jsfl script, it is essentially a spice of javascript running in flash platform. Here is my code:

    var folderURI = fl.browseForFolderURL("Please select the folder you want to recurse");
    fl.outputPanel.clear();
    var allFlas = [];
    var folds ;
    function listFile(paths){
    var files=[]
    var folds=[]    
    var files = FLfile.listFolder(paths + "/" + "*.fla","files"); 
    
    for(i=0;i<files.length;i++){
        allFlas.push(paths+"/"+files[i]);
    }
    var folds=FLfile.listFolder(paths,"directories");
    for(var j=0;j<folds.length;j++){    
        listFile(paths+"/"+folds[j]);   
    }

}
listFile(folderURI);
for(var i = 0; i < allFlas.length; i++)
{
var flaName = allFlas[i];

var doc = fl.openDocument(flaName);
var targetName = doc.name.replace(".fla","");
var cjsDataKey = "SwiffyToolkit_data";
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",
        "createjsNS", "createjs"
];
doc.addDataToDocument(cjsDataKey, "string", data.join("\n"));
doc.save();
doc.close(false);
doc = fl.openDocument(flaName);
fl.runScript(fl.configURI + "Commands/Export as HTML5 (Swiffy).jsfl");
fl.trace("Complete:"+i);
doc.close(false);

}
Let me give you some presentation about this,

  • When your double click this jsfl file, it will launch your flash app
  • Then run it, it’ll ask you locate to the directory which contents fla file.
  • And traverse all the subdirectories find all the fla files.
  • Execute Swiffy on every single fla file.
    5. Another problem is the swiffy script will open the generated html after compiling. That sucks!! We can change the swiffy jsfl to remove it. The step will be:
  • Change your zxp file extension name to zip.
  • Unzip it, you will see “Export as HTML5 (Swiffy).jsfl”
  • Open and edit it, comment code like this:
  • Repackage it with Adobe Extension Manager CS6.
  • Reinstall it.
    6. Also you might met a fucking dialog appears about font mapping, turn it down by Flash–> Preferences –> Text –>show for missing fonts.
    JSFL