The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 5 of 5

Thread: Flash with Ruby on Rails

  1. #1

    Flash with Ruby on Rails

    I want to know what is the best way to do the communication Flash-Ruby on Rails.
    I know about WebOrb, but i prefer a simpler thing because i only want to post a score of a game.

    thanks in advance!

  2. #2
    It's the same as any other server side technology. You have three options either:
    embed the flash with variables in the HTML in which case you just ouput them in the View.
    OR
    create a view which just has stuff like var1=something&... etc
    OR
    create a view which outputs XML data

  3. #3

    Barcode

    to add to this question,

    I managed to send data from Ruby to Flash and it all works finein that directiong by sending JSON strings through the views etc...

    but Flash => Ruby that I can't figure out!

    say we are sending variables with URLVariables form flash and hit the view html, how can we read these variables in Ruby?

    I couldn't figure that out! been googling all night and all day!

    to make it more concrete:
    I'm passing this JSON string form flash (encoded of course)
    {"call":"someMethode","id":"1"}

    Code:
    import com.adobe.serialization.json.JSON;
    
    // object holding the variables
    var testRequest:Object = {"call":"someMethode","id":"1"};
    
    // the url, Ruby view that I'm hitting
    var _request:URLRequest = new URLRequest("http://localhost:3000/flash/list");
    _request.method = URLRequestMethod.POST;
    
    // the URL variables I'm sending with the request
    var variables:URLVariables = new URLVariables();
    
    // I am using JSON to send/receive my data
    
    variables.request = JSON.encode(testRequest);
    
    _request.data = variables;
    
    // this is the loader
    var loader:URLLoader = new URLLoader();
    loader.addEventListener(Event.COMPLETE, onComplete);
    loader.load(_request);
    
    function onComplete(evt:Event):void
    {
        var arr:String = loader.data;
        var result:Object = JSON.decode(arr);
        trace (result.idCalled);
        trace (result.methodCalled);
    }
    how can i get Ruby to ready those variables "call" & "id" in order to store and use them inside my controller etc...


    pls help!

  4. #4
    Could you not just access the actual URL?

    http://localhost:3000/controller/method/id/extras/etc

    I don't use flash much so I don't know how they are passed to new pages, is it a POST request with a name?

  5. #5
    all worked great after further read.

    Like you've mentioned evildrummer, you call the related url's passing objects in 'POST' methods.

    say you have a TestController created in Ruby that accepts "data" param

    <mx:HttpRequest
    id="TestService"
    method="POST"
    result= "resultHandler"
    />

    function newData():void
    {
    var params:Object = new Object();
    params['_method'] = "POST";
    params['data[:name]'] = "My name";
    params['data[:last name]'] = "mylast name";

    TestService.url = "/test";
    TestService.send(params);
    }


    function updateData():void
    {
    var params:Object = new Object();
    params['_method'] = "PUT";
    params['data[:name]'] = "My name";
    params['data[:last name]'] = "mylast name";

    TestService.url = "/test/"+id;//this is to update test at id variable ex: "/test/1"
    TestService.send(params);
    }


    function deleteData():void
    {
    var params:Object = new Object();
    params['_method'] = "DELETE";
    TestService.url = "/test/"+id;//this is to delete test at id variable ex: "/test/1"
    TestService.send(params);
    }

    etc...

    using flash use URLRequest to hit those urls passing your params as URLVariables.

    In flash help they have a really good example search for URLVariables.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012