diff --git a/Assets/FlashTools/Examples/Animations/anim02.fla b/Assets/FlashTools/Examples/Animations/anim02.fla index 287251e..ea04023 100644 Binary files a/Assets/FlashTools/Examples/Animations/anim02.fla and b/Assets/FlashTools/Examples/Animations/anim02.fla differ diff --git a/Tools/FlashExport.jsfl b/Tools/FlashExport.jsfl new file mode 100644 index 0000000..aea60b1 --- /dev/null +++ b/Tools/FlashExport.jsfl @@ -0,0 +1,339 @@ + +var g_export_path = ""; +var g_library_path = ""; +var g_current_doc = null; +fl.showIdleMessage(false); +Main(); + +function Main() +{ + var documents = fl.documents; + if ( documents && documents.length ) + { + fl.saveAll(); + fl.outputPanel.clear(); + + for ( var i = 0; i < documents.length; ++i ) + { + g_current_doc = documents[i]; + ExportDocument(); + fl.closeDocument(g_current_doc, false); + }; + + alert("-= Process Complete =-"); + } +} + +function ExportDocument() +{ + var document_path = g_current_doc.path; + var last_slash = document_path.lastIndexOf("/"); + var last_dot = document_path.lastIndexOf("."); + + // g_export_path + var export_folder = document_path.substr(0, last_slash) + "/../" + document_path.substr(last_slash, last_dot-last_slash) + "_export/"; + g_export_path = FLfile.platformPathToURI(export_folder); + + // g_library_path + var library_folder = document_path.substr(0, last_slash) + "/LIBRARY/"; + g_library_path = FLfile.platformPathToURI(library_folder); + + // create export folder + FLfile.remove(g_export_path); + FLfile.createFolder(g_export_path); + + // run + ExportLibrary(g_export_path + "Library.xml"); +} + +function PrintNormal( text ) +{ + fl.outputPanel.trace(text); +} + +function PrintWarning( text ) +{ + fl.outputPanel.trace("-= PROCESS WARNING =-\n -- " + text); +} + +function ToRad( deg ) +{ + return deg * Math.PI / 180; +} + +function ExitEditMode() +{ + for ( var i = 0; i < 100; ++i ) + g_current_doc.exitEditMode(); +} + +function ExportLibrary( file ) +{ + ExitEditMode(); + + var doc = g_current_doc; + var library = doc.library; + var temp_layer = doc.getTimeline().addNewLayer("bme_temp_export_layer"); + var file_str = "\n" + + for ( var i = 0; i < library.items.length; ++i ) + { + var item = library.items[i]; + + if ( item.itemType == "folder" ) + { + // create folder + var path = g_export_path + item.name; + FLfile.createFolder(path); + } + else + { + if ( item.itemType == "bitmap" ) + { + file_str += + "\t\n"; + + // copy bitmap to export + FLfile.copy(g_library_path + item.name, g_export_path + item.name); + } + else if ( item.itemType == "movie clip" || item.itemType == "graphic" || item.itemType == "component" ) + { + file_str += + "\t 0 ) + { + var sel = doc.selection[0]; + if ( sel.parameters && sel.parameters.length > 0 ) + { + is_parameters = true; + file_str += ">\n"; + file_str = ExportParameters(sel.parameters, file_str, "\t\t"); + } + } + + if ( is_parameters ) + file_str += "\t\n"; + else + file_str += "/>\n"; + + // export item timeline + + library.editItem(item.name); + ExportTimeline(g_export_path + item.name + ".xml") + ExitEditMode(); + } + else + { + PrintWarning("Unsupported library type(" + item.itemType + ")"); + } + } + } + + FLfile.write(file, file_str + "", "append"); + doc.getTimeline().deleteLayer(); +} + +function ExportTimeline( file ) +{ + var doc_timeline = g_current_doc.getTimeline(); + + // [2:-] for disable dublicate single frame + if ( doc_timeline.frameCount > 1 ) + { + doc_timeline.selectAllFrames(); + doc_timeline.convertToKeyframes(); + } + + var doc_frames = doc_timeline.frameCount; + var doc_framerate = g_current_doc.frameRate; + + var file_str = "= 0; --i ) + { + var doc_layer = doc_timeline.layers[i]; + if ( !doc_layer || !doc_layer.visible ) + continue; + + file_str = ExportLayer(doc_layer, i, file_str, "\t") + } + + FLfile.write(file, file_str + "", "append" ); +} + +function ExportLayer( layer, index, file_str, prefix ) +{ + file_str += prefix + "\n"; + + for ( var i = 0; i < layer.frameCount; ++i ) + { + var frame = layer.frames[i]; + if ( !frame || i != frame.startFrame ) + continue; + + file_str = ExportFrame(frame, i, file_str, prefix + "\t"); + } + + return file_str + prefix + "\n"; +} + +function ExportFrame( frame, index, file_str, prefix ) +{ + file_str += prefix + "\n"; +} + +function ExportElement( element, index, file_str, prefix ) +{ + file_str += prefix + "\n"; +} + +function ExportInstance( instance, file_str, prefix ) +{ + // -------------------------------- + // parameters + // -------------------------------- + + if ( instance.parameters && instance.parameters.length > 0 ) + { + file_str = ExportParameters(instance.parameters, file_str, prefix); + } + + // -------------------------------- + // transform + // -------------------------------- + + file_str += prefix + " 0.01 ) + PrintWarning("Skew transformation unsupported! Element type(" + instance.libraryItem.name + ")"); + + var rotation = "'" + ToRad(instance.skewX) + "'"; + file_str += " rotation=" + rotation; + } + else + { + var rotation = "'" + ToRad(instance.rotation) + "'"; + file_str += " rotation=" + rotation; + } + + // -------------------------------- + // color + // -------------------------------- + + if ( instance.colorAlphaPercent ) + { + var alpha = "'" + instance.colorAlphaPercent / 100 + "'"; + file_str += " alpha=" + alpha; + } + + // -------------------------------- + // blend + // -------------------------------- + + if ( instance.blendMode ) + { + var blend = "'ALPHA'"; + if ( instance.blendMode == "normal" ) blend = "'ALPHA'"; + else if ( instance.blendMode == "add" ) blend = "'ADD'"; + else if ( instance.blendMode == "multiply" ) blend = "'MULTIPLY'"; + else PrintWarning("Unsupported blend mode(" + instance.blendMode + ")"); + + file_str += " blend=" + blend; + } + + return file_str + "/>\n"; +} + +function ExportParameters( params, file_str, prefix ) +{ + file_str += prefix + "\n"; + + for ( var i = 0; i < params.length; ++i ) + { + var param = params[i]; + + if ( param.valueType == "Number" || param.valueType == "Boolean" || param.valueType == "String" ) + { + var name = "'" + param.name + "'"; + var value = "'" + param.value + "'"; + var type = "'" + param.valueType + "'"; + + if ( param.valueType == "Number" ) + value = value.replace(",", "."); + + file_str += prefix + "\t\n"; +}