Archive for April, 2007

ASProject and Flash debugging to Firebug console

Thursday, April 12th, 2007

Publishing, testing, and running Actionscript projects is a pain.

“AsProject automates a variety of tasks including the creation of projects, classes, test cases, test suites, and swfmill libraries. It automates the download, installation and configuration of the debug flash player and many open source tools. AsProject also includes sophisticated build tools written in rake to automate build processes.”

Video demo or Project page


gem install asproject

Also, a friend Corey pointed out that you can debug flash using Actionscript ExternalInterface to log to Firebug console.log instead of using ASUnit’s debug console. In your actionscript:


 ExternalInterface.call("console.log", "FLASH: " + s);

And make sure to allowScriptAccess.

1
2
3
var so = new SWFObject("flash/xxx.swf", "myswf", "680", "200", "8", "#FFFFFF");
 so.addParam("allowScriptAccess", "always");
 so.write("xxx");

And you could call any javascript from it. ExternalInterface is a replacement for fscommand. I don’t remember but I don’t think ExternalInterface works in all browsers.

Rake test task for a custom FileList

Friday, April 6th, 2007

I work on a very large rails project, and rake test has become unruly mostly due to the size of our codebase. Anyway, I wrote this task to run only the tests in the products/namespace I work on.

rake test:products PRODUCTS=product1,product2

Runs all unit tests in test/**/product1/*test*.rb, test/**/product2/*test*.rb

The task:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
namespace :test do
  task :products do      
    raise "Usage: rake test:products PRODUCTS=product1,product2" if ENV['PRODUCTS'].blank?
    
    products = ENV['PRODUCTS'].split(/,/)
    files = []
    
    products.each do |product|
      dir = "#{RAILS_ROOT}/test/**/#{product}"
      files += FileList["#{dir}/*test*.rb"]
    end    
    
    test_task = Rake::TestTask.new("test_products") do |t|
      t.libs << "test"
      t.test_files = files
      t.verbose = true
    end
    
    task("test_products").execute           
  end
end

There is probably an easier way, but this works for me. Also I wouldn’t mind someone patching rake to accept opts style arguments, like –opt=blah, or -o blah. The ENV stuff seems really not so friendly.