Category: Flash/Actionscript


Tuesday 2007/08/28
10:43 AM

Categories:

Flash/Actionscript, Ruby/Rails, TextMate, Web Dev

A Quick RubyAMF Test

Update 2007-10-22: Updated the line with the RubyAMF installer to point to the new googlecode location. Updated the link to the SSR library.

Update 2007-08-30: Seth's comment below revealed the need for a cross-domain policy file in /public when testing this via the browser. I did all my testing from the flash debug player and the IDE, so I didn't run into this while writing this up. Aaron has said that he'll include the crossdomain policy file as part of the RubyAMF installer in the future.

Back from my Seattle/Portland vacation with Jordan (details on that to follow, but photos are up on Flickr).

Another quick Rails experiment, this time checking out RubyAMF. I wanted to run the RubyAMF gateway as a Rails plugin, so I used this Flex/Rails screencast on the RubyAMF blog as a reference for getting the Rails part done. You might want to view my earlier post on setting up Locomotive with MAMP.

I first created a new Rails app in Locomotive called test_hello_world (I also switched the port from 3001 to 3000). Once that was done I simply replicated the steps in the screencast:

  • Download RubyAMF.
  • Create a rubyamf folder in the test_hello_world/vendor/plugins directory.
  • Copy the contents of the RubyAMF download to the rubyamf directory.
  • Copy the rubyamf/services/rubyamf_controller.rb file to the test_hello_world/app/controllers directory.
  • As per Aaron's note below, use the rails installer. Type ruby script/plugin install http://rubyamf.googlecode.com/svn/trunk/rubyamf
  • Start the Rails app from Locomotive.
  • Test the RubyAMF gateway at http://localhost:3000/rubyamf/gateway.
  • Generate TestWorld controller. This can be done by opening a Terminal/iTerm session in the current Rails app context via the Locomotive > Applications > Open Terminal (Command-T) item. Once that's done you can type: ruby/script/generate controller TestWorld
  • Define a hello_world method in the controller to return the text string "Hello World!"

At this point the screencast goes into Flex, but I decided to make use of the Super-Simple Remoting (SSR) library from RubyAMF. I copied the source files to a folder containing my test AS3 script RemotingTest.as. Here's the contents of RemotingTest.as:

Actionscript:
  1. package
  2. {
  3.     import flash.net.Responder;
  4.     import flash.display.Sprite;
  5.     import org.rubyamf.remoting.ssr.*;
  6.    
  7.     public class RemotingTest extends Sprite
  8.     {
  9.         private var rs:RemotingService;
  10.        
  11.         function RemotingTest()
  12.         {
  13.             init();
  14.         }
  15.        
  16.         private function init():void
  17.         {   
  18.             trace("RemotingTest::init() ");
  19.             rs = new RemotingService("http://localhost:3000/rubyamf/gateway", "TestWorldController");
  20.             rs.hello_world([], onResult, onFault);
  21.         }
  22.                                                
  23.         private function onResult(re:ResultEvent):void
  24.         {
  25.             trace("RemotingTest::onResult() " + re.result.toString());
  26.         }
  27.        
  28.         private function onFault(fault:FaultEvent):void
  29.         {
  30.             trace("onFault: " + fault);
  31.         }
  32.  
  33.     }
  34. }

Note that when we create an instance of the Remoting service we pass it the path to the gateway, and the name of the controller which we just created (TestWorldController). Once that is defined we can then just call methods in that controller like so:

rs.hello_world([], onResult, onFault);

The empty array parameter is there because the method accepts no parameters.

I merely had the result piped to trace output, but you can have it piped to an onscreen text field as well if you don't have logging set up.

I was using the still-in-development AS3/Flex bundle (more on installing/modifying that in a following post) to compile RemotingTest.as into a SWF, but you should be able to link it as a document class to an FLA and generate the SWF that way.


Tuesday 2007/07/10
3:02 PM

Categories:

Flash/Actionscript, OS X, Ruby/Rails, TextMate, Web Dev

Locomotive on Rails, with MAMP as a Caboose

Update 2008-07-14: Looks like Locomotive is no longer being distributed, since OS X 10.5 now ships with Ruby on Rails installed.

Pretty soon we'll have a framework called "ChooChoo" just to take this metaphor to its logical demise. I've just started dipping my toe into Ruby on Rails, and have found it relatively easy to get up and running on OS X. I've been using a combination of MAMP and Locomotive. MAMP, of course, is the Macintosh/Apache/MySQL/PHP app that takes the pain out of setting up those respective components and allows you to focus on writing code. Locomotive is similar in that it takes care of setting up your Rails environment so you can start developing. In this situation MAMP is only being used for the MySQL component. I have a feeling Locomotive will eventually have this as part of its package, making things even easier.

There were two things I needed to do to get my setup working smoothly:

  • Tell Locomotive to use MAMP for MySQL. I did this by going to Locomotive > Preferences > Terminal and putting "/Applications/MAMP/db/mysql/" in the Additional Paths field.
  • From this tip at aralbakan.com: adding a socket definition to my database config file - “socket: /Applications/MAMP/tmp/mysql/mysql.sock”

I like that you can open up a terminal session from Locomotive and it'll set the context to be the Locomotive Rails environment - this way I don't have to mess with setting up my PATH to point to the Locomotive's Ruby instead of the default OS X one.

TextMate, of course, makes working with Ruby/Rails quite easy. I've been spending some time in Flex Builder lately, and coming back to the TextMate environment is a breath of cleaner, simpler air.

This was the tutorial I started out with: Using Ruby on Rails for Web Development on Mac OS X.

I also ran through the Merb/AIR tutorial here: Merb on AIR - Drag and Drop Multiple File Upload. Merb isn't Rails per se, but the example illustrates the way that Ruby apps can be used with AIR/Flash applications.


Thursday 2007/06/21
11:31 AM

Categories:

Flash/Actionscript, Web Dev, Work

Rush Hour 3 Plus Wii

More work going live...helped out a bit with the programming on this project, plus I show up as a stick-wielding baddie on the second stage since my coworkers and I ended up as the models for the characters.

Click on the 'Game' link under the trailer.

For those of you with a Wii, you can play the game by going to the site with the Wii browser.


Wednesday 2007/06/13
10:01 AM

Categories:

Flash/Actionscript, TextMate

AS3/Flex Review Bundle Installation

This will probably be in the next official release of TextMate, but until then I've been testing out the AS3/Flex bundle that's in development. Instructions for installation are available here. The only catch was that I had to explicitly set the path to my svn command in the script to '/usr/local/bin/svn'.

The bundle itself is nice. It's good to have more snippets and autocompletion options (especially for stuff like method and variable declarations). The debug menu also can pop open the flashlog.txt file in the console, which is nice for tracing from the browser.


Thursday 2007/05/03
10:09 AM

Categories:

Apple, Flash/Actionscript

Coda Now Does Actionscript

For the last few days I've been playing around with Coda, the new web development environment from Panic. It's a throwback to the old HomeSite-style editors, taking a site-level approach to web development. Daring Fireball had a nice writeup on the philosophy behind Coda, and how it differs from the prevailing web development tools currently available on OS X. I highly recommend that anyone doing web development with your bedrock HTML/CSS/[Scripting language] check it out. The UI is quite simple and beautiful, which is not a surprise to anyone who has used Transmit or CandyBar before.

I was initially disappointed with the app, not because I disagreed with the site-oriented approach, but because it simply didn't load Actionscript files. Attempting to map the .as file extension to Javascript didn't work, either. I put the app aside, thinking I'd check back in at version 1.5 or so.

Well, version 1.0.1 just dropped and Actionscript is now supported, so I'm back to playing around with it. The function list is much better than in TextMate, where it's hidden in a footer drop-down. I was hoping that class properties would also get entries in the list, but so far it's just functions. Again, this is only version 1, so I'm sure some of this stuff will find its way into future releases. At present the editor doesn't have the bundle/macro power of TextMate, so I doubt that I'll be switching over at this point. The future looks promising, though, and if they ever get site-level class browsing and Actionscript hinting like FlashDevelop I'll certainly be taking another test drive.