Created
October 25, 2015 11:51
-
-
Save jhiswin/58928a237f8a7ebd2f69 to your computer and use it in GitHub Desktop.
Batch convert Flash project to other format (HTML5 canvas) and export audio
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
// export audio because HTML5 canvas projects mangles published audio files | |
// TODO find way to click ok buttons, so it is fully automatic | |
var inFolder = fl.browseForFolderURL("Select a folder with Flash files."); | |
var imageFileURLBase = inFolder + '/sounds'; | |
fl.trace(inFolder); | |
var files = FLfile.listFolder(inFolder + "/*.fla", "files"); | |
var fileURI; | |
for (fileURI in files) { | |
fl.trace(fileURI = inFolder + '/' + files[fileURI]); | |
var doc; | |
// is canvas project or published js already exists | |
if (fileURI.indexOf('_Canvas.fla') >= 0 || FLfile.exists(fileURI.slice(0,-4)+'_Canvas.js')) continue; | |
// not canvas project | |
if (fileURI.indexOf('_Canvas.fla') < 0) { | |
//canvas project exists, don't convert, just open canvas project | |
if (FLfile.exists(fileURI.slice(0,-4)+'_Canvas.fla')) | |
doc = fl.openDocument(fileURI.slice(0,-4) + '_Canvas.fla'); | |
else { // no canvas project, convert | |
doc = fl.openDocument(fileURI); | |
fl.trace(fl.configURI + 'Commands/Convert to Other Document Formats.jsfl'); | |
fl.runScript(fl.configURI + 'Commands/Convert to Other Document Formats.jsfl'); | |
doc.close(false); | |
doc = fl.getDocumentDOM(); | |
} | |
} | |
fl.trace(fileURI = inFolder + '/' + files[fileURI]); | |
var lib; | |
if (doc.library.getSelectedItems().length > 0) { | |
lib = doc.library.getSelectedItems(); | |
} else { lib = doc.library.items; } | |
var imageFileURL; | |
var totalItems = lib.length; | |
// Iterate through items and save bitmaps and | |
// audio files to the selected directory. | |
for (var i = 0; i < totalItems; i++) | |
{ | |
var libItem = lib[i]; | |
if (libItem.itemType == "bitmap" || libItem.itemType == "sound") | |
{ | |
// Check the audio files original Compression Type if "RAW" export only as a .wav file | |
// Any other compression type then export as the libItem's name defines. | |
if(libItem.itemType == "sound" && libItem.originalCompressionType == "RAW") | |
{ | |
wavName = libItem.name.split('.')[0]+'.wav'; | |
var folders = wavName.split("/"); | |
var folderuri = imageFileURLBase; | |
for(var j = 0; j < folders.length - 1; j++){ | |
folderuri = folderuri + '/' + folders[j]; | |
FLfile.createFolder(folderuri); | |
} | |
imageFileURL = imageFileURLBase + "/" + wavName; | |
} else { | |
imageFileURL = imageFileURLBase + "/" + libItem.name; | |
} | |
var success = libItem.exportToFile(imageFileURL); | |
fl.trace(imageFileURL + ": " + success); | |
} | |
} | |
doc.publish(); | |
doc.close(false); | |
} |
Bump (8 months later, no reply)
Hey reyco1, I think Adobe Animate CC already has an option to convert Flash content to HTML5 canvas.
On Adobe Animate CC, open your Flash project, then click "Commands" then click "Convert to other Document Formats" and that's how you can convert your Flash animation into HTML5 canvas.
You can execute fl.supressAlerts
to stop Animate alerts. Hope that helps.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey man, did you ever figure out how to have it automatic? Im speaking in regards to not haiving to click the "OK" button all the time