Skip to content

Instantly share code, notes, and snippets.

@osi
Created January 16, 2009 23:22
Show Gist options
  • Save osi/48206 to your computer and use it in GitHub Desktop.
Save osi/48206 to your computer and use it in GitHub Desktop.
"Publish" a folder of FLA files using Flash CS3/4
#!/usr/bin/env ruby -wKU
require "fileutils"
def generate_jsfl(fla, log)
return <<EOF
var sourceFile = "file://#{Dir.pwd}/#{fla}";
var logFile = "file://#{log}";
var doc = fl.openDocument(sourceFile);
fl.outputPanel.clear();
fl.compilerErrors.clear();
fl.getDocumentDOM().publish();
fl.outputPanel.save(logFile, true);
fl.compilerErrors.save(logFile, true);
fl.getDocumentDOM().close(false);
EOF
end
def publish(fla)
puts "Publishing #{fla} ..."
log = "/tmp/publish/output"
jsfl = generate_jsfl(fla, log)
# puts jsfl
FileUtils.rm log, :force => true
jsfl_script = "/tmp/publish/go.jsfl"
File.open(jsfl_script, 'w') { |f| f.write(jsfl)}
`open --background #{jsfl_script}`
while not File.exist? log
sleep 1
end
sleep 2 # another 2 for good measure
contents = File.new(log).read
contents.gsub! "\r", "\n"
if contents.length > 3
STDERR.puts "Unable to build #{fla}:\n"
STDERR.puts contents
exit 2
end
end
FileUtils.mkdir_p "/tmp/publish"
if ARGV.empty?
puts "Publishing src/*.fla"
Dir.glob("src/*.fla") { |fla| publish fla }
else
ARGV.each { |fla| publish fla }
end
puts "Publish complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment