Using document type converter in Animate CC

To convert your current document to any other document type, click File > Convert To and choose the desired document type. The following screenshot depicts the document conversion option from HTML5 canvas document type to other available formats.

file-convert-to
List of allowed document types for conversion

HTML5 Canvas document type does not support multiple scenes. When you try to convert any multi-scene document to HTML5 Canvas document type, all the scenes are saved as separate files. Place all your scenes in separate symbols if you want to use them in a single document.

Pastaba:

You can convert your existing Animate projects to another format or reuse assets in a project by copying and pasting layers or library symbols. 

Converting to other document types using JSAPI

If you have custom scenarios in which you want to convert files to other document types, then you can use the JSAPI. For example, converting many files at a time into other document types. 

convertToDoc method

Description Usage Parameters Return value
Converts a document to expected document type. document.convertToDoc(fileURI, doctype, fileClose)

fileURI A string, expressed as a file:/// URI, that specifies the path of the generated file after conversion.

docType A string value that specifies the required document type to be generated. To find document type, you can use document.type property. For example, fl.trace(fl.getDocumentDOM().type)).

fileClose (optional) A Boolean value that specifies whether to close the generated file after conversion. Specifying true closes the generated file. The default is false.

A Boolean value.

True if document converted to expected document type successfully.

False otherwise.

Some of the sample scripts are provided below for your reference. 

Convert all files from a folder to other document type

The following jsfl script converts all the fla files placed inside a folder named convertToJSAPI to HTML5 Canvas doc.

var str = fl.scriptURI;
var url = str.substring(0, str.lastIndexOf("/"));
var folderURI = url + "/convertToJSAPI/";
var fileMask = "*.fla";
var list = FLfile.listFolder(folderURI + "/" + fileMask, "files");
fl.trace(folderURI);
if (list) {
for(var i=0;i<list.length;i++)
{   
	var fileURI = folderURI + list[i];
	var doc = fl.openDocument(fileURI);
	fl.trace(folderURI);
    doc.convertToDoc(folderURI+'Convertedfla'+i+'.fla',' htmlcanvas');

}
}

Convert last active document to other document type

var str = fl.scriptURI;
var url = str.substring(0, str.lastIndexOf("/"));

var doc = fl.getDocumentDOM();
//doc.convertToDoc('url','htmlcanvas');
doc.convertToDoc(url +'/RotationCamera2.fla','htmlcanvas');

Convert all active documents to other document type

var str = fl.scriptURI;
var url = str.substring(0, str.lastIndexOf("/"));

for(var i=0;i<fl.documents.length;i++)
{
	fl.trace(fl.documents[i].name);
	fl.trace(fl.documents[i].type);
	fl.documents[i].convertToDoc(url +'/abc'+i+'.fla','webGLDoc',true);
}

Browse for a document and convert it to other document type

var fileURI = fl.browseForFileURL('open','open');
var doc = fl.openDocument(fileURI);
var sr = "";
sr +=fileURI;
fl.trace("ajit"+fileURI);
var str = sr.substring(0, sr.lastIndexOf("/")); 
fl.trace("arvind"+str);
 doc.convertToDoc( str+"/test.fla" ,'Flash',true);
//doc.convertToDoc('fileURI','htmlcanvas',true);
//doc.convertToDoc('fileURI','WebGlDoc',true