Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@noirotm
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noirotm/3ef2f82655879d5d800e to your computer and use it in GitHub Desktop.
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.
=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