「RubyAMF」の編集履歴(バックアップ)一覧に戻る

RubyAMF - (2008/01/13 (日) 15:28:44) の編集履歴(バックアップ)


プラグイン名

RubyAMF

このプラグインができること

  1. フロントエンドとなるFlashと、バックエンドとなる「何か」をつなぐためのAMF0またはAMF3を、Flash・RubyonRails間で使うためのプラグイン
  2. AMFはバイナリとしてデータ転送するので、大量のデータ転送時に効率が上がる(データ量や時間など)
  3. (自分自身まだよくわかってないものの)RPC的な使い方がメイン?
  4. ActionScript3用のFlash RemotingライブラリであるSuper Simple Remoting(http://ssr.riaforge.org/)を使うと、楽が出来る。

対象バージョン

1.2系

ちょー簡単な使い方

Rails側
ruby script/plugin install http://rubyamf.googlecode.com/svn/trunk/
でインストールして、普通のコントローラーを作って
ruby script/generate controller sample
普通のコントローラーにアクションを定義して
class SampleController <ApplicationController
 def helloworld
   render :amf => "HelloWorld"
 end
end

Flash(Flex)側
Super Simple Remoting(http://ssr.riaforge.org/)をインストールして、アクションスクリプトで
import org.rubyamf.remoting.ssr.RemotingService;
import org.rubyamf.remoting.ssr.ResultEvent;
import org.rubyamf.remoting.ssr.FaultEvent;
public class Main extends Sprite {
 public function Main() {
   var serv:RemotingService = new RemotingService(
     "http://192.168.1.160:8181/rubyamf/gateway",
     "SampleController"
   );
   serv.helloworld([], on_result, on_fault);
 }
 private function on_result(evt:ResultEvent):void {
   trace(evt.result);
 }
 private function on_fault(evt:FaultEvent):void {
   trace("ERROR");
 }   
}
ってやると、
serv.helloworld([], on_result, on_fault);
により、Flash側からRails側のsampleControllerのhelloworldアクションがパラメータなしで呼ばれて、成功時ハンドラon_result,失敗時ハンドラon_faultのどちらかがコールされる。

もし
serv.create([ {last_name:last_name.text, first_name:first_name.text} ], on_result, on_fault);
とやると、Rails側ではsampleControllerのcreateアクションの中で
params[0][:first_name]
params[0][:last_name]
でアクセスできる。

公式ページ

http://code.google.com/p/rubyamf/
※RubyForgeから引っ越したみたい
ここのサンプルソースも使えるかも。(まだ見てない)


日本語解説ページ

※チュートリアル風にRails→Flashでの受け取りまで。
※Flash(Flex)→Railsの呼び出し

外国語解説ページ

Beginner's Tutorial to RubyAMF with RESTful Rails
※本家以外で初心者用の良いチュートリアルは今のところ見つけられていない。てか、本家もあまりドキュメントとしては良くない。

のうはう

ええと、SSRに関する資料が不足しているな。
まず、ダウンロードとかsubversionリポジトリをチェック。
ここのサンプルソースは見ておくべし
カスタムエラー処理の書き方
あと、認証失敗処理も書けるみたい



コメント