Last active
August 29, 2015 14:07
-
-
Save noirotm/3ef2f82655879d5d800e to your computer and use it in GitHub Desktop.
Ruby script for Windows using JSFL to compile a .fla file into a .swf.
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
=begin | |
This script leverages JSFL to automatically build a FLA file. | |
=end | |
require 'pathname' | |
require 'tempfile' | |
require 'win32/registry' | |
# input and output filename | |
input_filename = Pathname(File.dirname(__FILE__)) + ARGV[0] | |
output_filename = Pathname(File.dirname(__FILE__)) + ARGV[1] | |
input_url = "file:///" + input_filename.to_s.sub(':', '|') | |
output_url = "file:///" + output_filename.to_s.sub(':', '|') | |
# locate Flash | |
flash = nil | |
Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Flash.exe') do |reg| | |
flash = Pathname(reg[nil]) | |
end | |
# error log | |
errorfile = Tempfile.new(['flash', '.log']) | |
errorfile.close | |
error_url = "file:///" + errorfile.path.sub(':', '|') | |
# generate a JSFL file | |
js = <<EOJS | |
var doc = fl.openDocument("#{input_url}"); | |
doc.exportSWF("#{output_url}", true); | |
fl.compilerErrors.save("#{error_url}", false, true); | |
doc.close(false); | |
fl.quit(); | |
EOJS | |
jsfile = Tempfile.new(['flash', '.jsfl']) | |
jsfile.write(js) | |
jsfile.close | |
# Execute the file | |
system("\"#{flash}\" \"#{jsfile.path}\"") | |
# print errors and exit 1 if necessary | |
errorfile.open | |
errortext = errorfile.read | |
nerrors = errortext.split(/[\r\n]+/)[-1][/^\d+/].to_i | |
nwarnings = errortext.split(/[\r\n]+/)[-1][/, \d+/].to_i | |
if nerrors > 0 | |
$stderr.puts errortext | |
exit 1 | |
end | |
if nwarnings > 0 | |
$stderr.puts errortext | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment