views:

733

answers:

3

Quite a few methods exist for passing data into a Flex binary from a Rails application. Right now, I'm using the old e4x resultFormat with a xml.erb template. I've done AMF before, but I feel like inlining parameters into the embed itself is a better solution because you don't have to wait for the browser to load a swf binary and the binary to make a web request.

Taking all of that into account, what is the best practice for rendering a Flex widget with a Rails back-end these days?

+1  A: 

Sounds to me like you shouldn't use Flex at all. Flex is great for writing applications that load and display data, but is a huge overhead if you just want to display charts. If you're worried about delivering the SWF and the data in two separate responses, you should be worrying about the 200-300 K overhead of the Flex framework.

Go with something more lightweight like Flot and deliver the JavaScript code that generates the charts along with the data. I don't think Flex is a suitable platform for what you want.

Theo
Google analytics and finance use SWF-based charts (not sure if they're Flash or Flex though). It seems like SWF charts do a better job with larger volumes of data than JS ones.
hoyhoy
A: 

If the chart is just a graphic you are placing amidst normal html content, your solution of custom compiling the swf may be a good one. Of course you should still explore alternatives like Theo's suggestion.

If your whole application is flash, it's a toss-up. If it is fastest to simply import a swf, go ahead. However, if you need to make things any more interactive, use the data elsewhere, or fetch new data, it would probably be best to use xml templates as you are, or the ActiveRecord::Base#to_xml method if you're lazy.

Nick Retallack
I'm using a dataprovider with to_xml now. But, I'm wondering when it is more appropriate to just parametrize all the data into an embed tag versus making another http call.
hoyhoy
A: 

It depends, are you going to want the charts to be 'live', as in get updated in real-time when data changes? If so then using AMF with a Flex native RemoteObject gives you plenty of polling options, you can also just use a simpler Flex native HTTPService.

Read about them both here: Flex Actionscript 3.0 Documentation

defmeta