Daniel's Stuff

I write code

Month: September 2006

TextMate and Flex 2

I’ve been having a bit of a play with Adobe’s Flex 2 command line compiler. After doing a quick search around the net I found a couple of hints for using it with TextMate. Unfortunately none of them did quite what I wanted, so I built my own. Hopefully it will be useful for others 🙂

TextMate bundle for Flex 2 coding

It adds a new language type for mxml files, a few snippets with mx as the tab trigger and a build command bound to Command-B.  By default it looks for your Flex install in the following places

  1. ~/Flex
  2. ~/flex_sdk_2
  3. /Developer/SDKs/Flex
  4. /Developer/SDKs/flex_sdk_2
  5. /Developer/Applications/Flex
  6. /Developer/Applications/flex_sdk_2
  7. /Applications/Flex
  8. /Applications/flex_sdk_2

Any errors or warnings are displayed in the output window and a click will take you to where the problem is.

Once your Flex app is building successfully it will be opened in Safari, or if you have a script called deploy in the same folder as your mxml file it will be executed instead.

Enjoy 🙂

before_create considered harmful

I had a fsck of a time today working with rails. Normally I love Ruby on Rails, but today it gave me the screaming shifts!

I had a model class to which I wanted to add some sensible default values to satisfy some constraints in the database.
The logical place for that was before_create, so I did something like the following

class MyModel < ActiveRecord::Base

def before_create

self.foo ||= true
self.bar ||= Time.now
self.baz ||= false

end

end

Now, I would have thought that would work, but whenever I tried to save an instance of my class to the database the save method would return false 🙁
Hmmmm. Ok, let’s add some logging code and see what the problem is… Are there any errors? Nope. Does the instance think it’s valid? Yes. OK, that’s weird. Maybe there is something going on and the exception is getting eaten by some other code in the application (there are three of us working on this code and we’re not all in the same state, so who knows what one of the others may have done 😉 ). I try creating an instance using the rails console. Same thing (which is to be expected, but I was starting to get a little desperate by this stage).

What was the next thing to do? Go through the code and remove things line by line until I start getting some exceptions. Finally in desperation I took out my before_create method, and lo and behold my error messages come back. It was then that I was struck by the thought that Ruby methods take their return value from the last expression evaluated in their body, so the before_create method was returning false. It seems that there is a nice undocumented “feature” in ActiveRecord that allows application code to stop an object being saved to the database by returning false from before_create, and I imagine before_save.

A little note to that affect in the documentation would have saved me quite a bit of time today.

Ah well. Live and learn I guess 🙂

flvThing is released

I’ve released flvThing on the www.automagic-software.com web site. It seems to play every flv file I’ve thrown at it quite nicely 🙂 
The flv files are played using the installed flash player which is hosted inside a WebView control. The application creates a tiny very stupid web server that serves up the flash files as well as the flv file for the flash player to load. It seems to work pretty well 🙂

OmniGraffle is SO cool!

I’ve been building a simple little app to play FLV files on the Mac and I should be releasing it some time over this weekend. I needed to make some icons and I threw them together in OmniGraffle Pro. Go check out www.omnigroup.com for more details. 
 
I’ve used it a few times for this sort of thing. Here’s an example of what som
ebody who has no graphic design skills can accomplish very quickly 😉 
 
 
 
 
I’m pretty happy with it 🙂 It looks pretty good shrunk down to 128×128 and the alpha channel comes out when I export is as a PNG 🙂