interchange data with flex/flash

Events happening in the community are now at Drupal community events on www.drupal.org.
monti's picture

we are a drupal developer and a flex/flash developer working ad-hoc on a mutual project, where data needs to be sent back and forth between drupal and a flash application.

requirements :

  • the flash application lets the user to visually create a complex pattern, that is stored internally in a flex structure.
  • users may save their creations along with some information (name, email, private/public, etc.)
  • users may retrieve their own creations to a sort-of gallery (a player copy of the above application), select one and keep on editing it.
  • users may watch other people creations, provided that they are set as "public"

we were looking into services & amfphp and since it is our first ever integration, we are seeking an approval that this is indeed the right direction. any other tips are of course appreciated as well.

cheers !

Comments

Yes, here are some pointers

johnstorey's picture

Services is the standard way to solve this. Traditionally the Services AMFPHP Server has been used for this, but I've also gotten it working smoothly with JSON.

There is a book on the topic, with a great class you can drop in your code:

http://www.amazon.com/Flash-Drupal-Travis-Tidwell/dp/1847197582/ref=sr_1...

There is also a class linked from this group here:

http://groups.drupal.org/node/82994

I hope that points you in the right direction. Services has turned Drupal into an integration server for one of my cilents. He even had someone else build a website that pulls data from Drupal to build it's pages. That made me a little sick to my stomach, but it happened while I was on vacation and was too far gone to stop when I got back. :)

Sounds reasonable

waldmanm's picture

I'm using services and amfphp for similar purposes - a Flex app that allows users to collaborate on manipulating a complex set of data.

Some links I found useful:

http://electricpineapple.net/2009/03/10/api-keys-to-the-city-setting-up-... - the best tutorial I found on connecting to Drupal from Flex. I noted a couple of gotchas in a comment on this post (almost at the bottom).
http://groups.drupal.org/node/2768 - a simpler example, but without authentication, so was less useful to me.
http://drupal.org/node/187998 - another example, with a pointer to how to expose additional drupal functionality to Flex.

http://www.dpdk.nl/opensource/drupalproxy-as-a-bridge-between-flash-as3-... - this is an open source package that takes care of all aspects of connecting from Flex to Drupal. I'm not using it as I developed my own code prior to seeing it, but it's a second generation of this package and seems worthwhile checking if you're starting from scratch.

http://raghuonflex.wordpress.com/2008/06/05/endpointatruntime/#comment-5324 - Not being very familiar with Flex, I had a problem of how to specify the drupal server at run time (to use different servers for development and production, for example). This post got me in the right direction.

http://www.asual.com/swfaddress/ - for handling URL based navigation within Flex, if you need it.

Other tips:

  • Part of the difficulty is to understand the data representation for info you get from Drupal and how to structure what you send back to Drupal. You would expect the formats to be the same, but that is not the case (for example, between node.get and node.save). See this comment and the post it's in: http://drupal.org/node/275045#comment-1945326. It's easy to see what you get from Drupal services - you just set a break-point in Flex and inspect the data. It's a little trickier to send data back in the right format.

  • As mentioned in the above comment, taxonomy is one such example. Here's the comment for the Flex function I wrote to massage taxonomy from what node.get provides to what Drupal expects on a node.save:

    /***
     * transform 'taxonomy' into what Drupal expects on node save.
     * Typically, a req's 'taxonomy' is an array of TaxonomyTerm's indexed by tid (this is what Drupal returns).
     * However, the node.save method expects a two-layer array (array of arrays), where the first array is
     * indexed by vid, and for each vid there is an array of that vocabulary's terms (indexed by tid). 
     * An exception is those taxonomies which are free-tagging ('tags'). These are all contained as the 
     * value of the master array item with a key of 'tags' (i.e., one more level of nesting). This value is 
     * an array indexed by vid's with each vid having as a value a string containing a list of comma-separated
     * tag names.
     * Note that all vocabularies must be included in this array, even those that don't have any terms 
     * associated with this node, so as to remove the last term in a vocabulary if needed (indicate an empty
     * vocabulary).    
     ***/
    

    (I'd post the function itself but it's a bit specific to my data structures and how I use Drupal). See also http://drupal.org/node/507650.

  • Also, some node fields do not get returned with views.get (see more at http://drupal.org/node/678202). If you're comfortable with Drupal and run into such problems, it might be easier to bypass views and use a customer service you develop yourself (I've done a few, it's not too difficult).

Hope this helps get you on the right track. If you run into problems - this is a helpful forum to post questions to.

Micah

thanks guys

monti's picture

have just seen these responses and am checking all the valuable information right now.
thanks again !!!

very possible

rolf vreijdenberger's picture

Hi Monti,

what you want to do is certainly very possible. We use the combination of drupal and flash/flex all the time for complex applications with drupal acting as the cms of choice for the flash frontend.

The book by travis tidwell is good and the DrupalProxy class that is linked in two of the above posts removed some of the shortcomings from the code in that book (most notable the lack of unlimited arguments when calling services and code bloat). It also features a very strong and consistent api so it should make you life easy.

the 17th of november I will be speaking at the adobe usergroup XL event in the netherlands about integrating flash and drupal. The session's video will be put up on the net after the event.

good luck

Kind regards,

Rolf Vreijdenberger

drupal and flash: http://www.dpdk.nl/opensource/drupalproxy-as-a-bridge-between-flash-as3-...

presentation and demo code online

rolf vreijdenberger's picture

Hey Monti,

I've put the presentation and the demo code online. the presentation is in dutch, but the demo code's extensive comments are in english and well organized. you might want to check it out.
http://www.dpdk.nl/opensource/presentation-and-code-of-the-adobe-user-gr...

Kind regards,

Rolf Vreijdenberger

drupal and flash: http://www.dpdk.nl/opensource/drupalproxy-as-a-bridge-between-flash-as3-...

Zend AMF

BOGUƎ's picture

Zend AMF (http://framework.zend.com/manual/en/zend.amf.server.html) is another option, i've been using it for a while now -- AMFPHP seemed abandoned at the time. In fact, i showed up here while looking into ways to better integrate it in Drupal, i might have more to contribute down the line.

Good luck,
Jeff Gauthier

any news on that

rolf vreijdenberger's picture

Hi Jeff,
is there any progress on that front. ZendAmf in drupal would rock. Anything you have or that I/we (my company dpdk) can help out with?

cheers

Kind regards,

Rolf Vreijdenberger

drupal and flash: http://www.dpdk.nl/opensource/drupalproxy-as-a-bridge-between-flash-as3-...

Zend AMF

BOGUƎ's picture

Hey Rolf,
Funny you should ask, i've picked the gauntlet back up no later than yesterday. I was able to transfer gateway control over to the Services modules, now i have to have it actually handle authentication. Should have a proof of concept going soon.

Proof of concept

BOGUƎ's picture

A first shot at a contribution to the Drupal effort: here's the ZendAMF module. Installation is pretty straightforward:

  • Download the zendamf-7.x-1.x-dev.tar.gz
  • Unpack in "sites/all/modules/services/servers" (this assumes "Services" is already installed)
  • Download the latest ZendAMF and unpack in "sites/all/libraries"
  • Create the service's endpoint (Admin > Configuration > Web Services > Services)
  • Use 'zendamf' for everything for now ;)
  • Don't forget to active the resource you want to use!

Hopefully, you will have a gateway going at http://your_site/zendamf, feel free to check. I just pust together a quick AS3 example in the "./as3" folder that calls the "node.retrieve" resource, so don't forget to enable it!

Caveat emptor: this is a proof of concept, barely an alpha release provided for development purposes only!

Great that you have begun

rolf vreijdenberger's picture

Great that you have begun working on this, a zendamf implementation would absolutely ROCK!!!! thanks for picking up the gauntlet.

I have some things I don't understand and some feedback if I may.

First of all, the enabled resources (node.retrieve, user.login etc) that I enable do not show up in the list of enabled services.
Granted, I have not worked with the new services so maybe I'm doing something wrong and this has nothing to do with the zendamf server

second: I see that you call the method zendamf_call in your actionscript class and do some arguments juggling in that method on the drupal side to make it work.
This breaks all existing client side actionscript implementations (including ours:)). While it probably works, this would not be a great option, especially so, since if this module gets more functionality, we also have to work with authentication etc. adding complexity and it is not a standard way to implement remoting functionality on the server

here's some debug information from Charles (httpsniffer, charlesproxy) after calling system.connect which is the "status" information from the zendamf call. This happens because I use the 'normal' way of using amfremoting using the DrupalProxy class I wrote. Because of this, the DrupalProxy class can even work with non drupal systems by using amfremoting. You see that the 'normal' way of doing amf is not working, I think this is highly undesirable. To be clear, I'm grateful that you're working on this and am merely pointing out something that should be addressed imo, please don't hold it against me :) I understand it is just a proof of concept

Class "system" does not exist: Plugin by name 'System' was not found in the registry; used paths:

0 /home/vreijdenb/domains/vreijdenberger.nl/public_html/drupal7/sites/all/libraries/Zend/Amf/Server.php(539): Zend_Amf_Server->_dispatch('connect', Array, 'system')

1 /home/vreijdenb/domains/vreijdenberger.nl/public_html/drupal7/sites/all/libraries/Zend/Amf/Server.php(629): Zend_Amf_Server->_handle(Object(Zend_Amf_Request_Http))

2 /home/vreijdenb/domains/vreijdenberger.nl/public_html/drupal7/sites/all/modules/services/servers/zendamf/zendamf.module(29): Zend_Amf_Server->handle()

3 /home/vreijdenb/domains/vreijdenberger.nl/public_html/drupal7/sites/all/modules/services/services.module(244): zendamf_server()

4 /home/vreijdenb/domains/vreijdenberger.nl/public_html/drupal7/includes/menu.inc(499): services_endpoint_callback('zendamf_server')

5 /home/vreijdenb/domains/vreijdenberger.nl/public_html/drupal7/index.php(22): menu_execute_active_handler()

6 {main}

cheers

Kind regards,

Rolf Vreijdenberger

drupal and flash: http://www.dpdk.nl/opensource/drupalproxy-as-a-bridge-between-flash-as3-...

Aaaargh... forgot to mention:

BOGUƎ's picture
  1. Aaaargh... forgot to mention: the resources weren't showing up here either with RC1. I installed the dev version and POUF! there it was! That's when the whole Services thing started making sense to me.
  2. zendamf_call: aaaaah.. i'm a Drupal newbie -- started work directly on V7; i'm guessing you've been using an earlier version. I just figured i'd sift all traffic through a function to start off -- no need to get into anything complex at this point.

    Regarding proper amf handling: If you have an example of how the call should be properly handled, i'll gladly mod it. Not sure i would qualify anything i do as "coding" anyway -- more like "hacking" in the less glamorous sense of it. I just needed a quick setup for a few Flash websites here, so i put that thing together and figured i'd share in the hope it would get the ball rolling on something more elaborated and secure. Having all traffic handled by the Services module instills a sense of security anyway, that's why i feel comfortable using this in spite of its simplicity.

Anyway, glad to see things are moving too!
G'day! Jeff

Great that you have begun

rolf vreijdenberger's picture

accidental double post

Kind regards,

Rolf Vreijdenberger

drupal and flash: http://www.dpdk.nl/opensource/drupalproxy-as-a-bridge-between-flash-as3-...

D6 services 3?

dajuice's picture

Will the 7.x module work with the 6.x-3.x Services module by any chance? I really would love to have a proper AMF module for 6.x-3.x while we wait for 7.x to be peady for primetime with more modules /themes ported over.

drupal dev days

rolf vreijdenberger's picture

Hi Jef,

I just talked to some of our developers, they are at the drupal dev days as we speak, in Brussels, participating in a code sprint and working on the zendamf implementation. So there will be some development on this done there. They are having a look at your work, things are in motion!

Kind regards,

Rolf Vreijdenberger

drupal and flash: http://www.dpdk.nl/opensource/drupalproxy-as-a-bridge-between-flash-as3-...

Drupal 6 with Flash Builder 4

dajuice's picture

Im trying to get to connect Flash Builder 4 to drupal but have run into lots of issues trying to figure out the best route / most likely to be supported in a migration to 7. Im actually building a new site for someone right now and the flash integration is key to a tool im designing but i find that Drupal 7 is lacking too much in support, most of the modules are in beta/alpha and even the templates arent there yet. I would like to stick with 6 for now until 7 get more support.

My issue is that there seems to be a lack of development and/or support for the older version.
There is Services 6.2 which is stable, but SOAP is only available for v6.1 with a patch to make it work for 6.2 (which is what im testing now)
AMFserver seems stuck in limbo between with AMFServer instead of moving to ZEND, but now i see your developing ZEND for 7, will it work for 6? Even if i get AMF working in 6.2 im having issues trying to figure out how to connect it with Flashbuilder 4 since it seems to want to use ZEND
XMLRPC i tried as well but again there is some integration missing and everything is outdated and not for Flash Builder 4

Any suggestions would help at this point. I've spent probably about 20 hours trying to get SOAP connected which seems to be my best hope without having to write a huge list of modules for FB4.

Trust your feelings, Luke...

BOGUƎ's picture

Disclaimer: Off the bat, i'll point out that i know next to nothing of Flash Builder (i use FlashDevelop) and i'm still learning the Drupal ropes (i went straight for V7 while it was being developed), and i am not affiliated with the most excellent Services module group, whose member may consider the following heresy (wouldn't blame them :)

I'd definitely put in the time getting AMF to work -- AMFPHP or ZendAMF, they aren't that much different in the end; anything to avoid XML (why use it when you can deal directly with arrays and objects with AMF?).

If time is an issue and you're just using Flash on your site (as opposed to having it run from a remote location), maybe you could bypass the Services module for this specific project, and work it back in a little later if need be. Granted, you're not benefiting from the soothing comfort of Services, but at least you'll have something going.

Here's a ZendAMF Gateway in its simplest form (this assumes you've unpacked the ZendAMF classes in sites/all/libraries):

function zendamf_server() {
 
    ini_set('include_path', get_include_path() . PATH_SEPARATOR . DRUPAL_ROOT . '/sites/all/libraries');
    require_once 'Zend/Amf/Server.php';

    $server = new Zend_Amf_Server();
 
    $server->setProduction( false ); //SET TO TRUE WHEN YOU GO LIVE!
    $server->addFunction('zendamf_call');
       
    $handle = $server->handle();
    echo $handle;

}

function zendamf_call(){
    return "WOOHOO!";
}

And this is the AS3 part of it:

//connection to the server
var conn:NetConnection = new NetConnection();
conn.objectEncoding = ObjectEncoding.AMF3;
conn.connect('http://your_site/your_amf_gateway');

//the call itself
conn.call('zendamf_call', new Responder(onResult, onError), var1, var2, ...);

private function onResult(o:Object):void{
   //hopefully, this will return 'woohoo!'
    trace('Success: ' + o);
}

private function onError(o:Object):void{
    // Scream!!!
    trace('##Error## ');
    trace(o);
}

This being said, i can't stress this enough: this should be seen as a temporary solution to a specific issue. Ultimately, you WANT to rely on the work provided, and more importantly, validated by the community, be it Services or any module for that matter; in this particular case, there are potential security issues to be aware of -- i certainly wouldn't rely on this to interact with sensitive information in this stripped-down form. But desperate times begging for desperate measure, going simple may be the way to do it.

I originally started by

dajuice's picture

I originally started by testing the AMFPHP but i ran into issues with Flash Builder since it was pretty closely tied to ZEND. I really wanted to be able to use the Data Centric Wizard thats part of Flashbuilder which basically connects to your service, returns all your functions etc without having to do the code. However I guess in the end this will take some time before we get a module that plays nicely with all the fun tools of FB 4.

In the meantime I still think Drupal 7 is too early in its infancy considering that many modules are still in alpha / beta.

That being said, can someone tell me if the services module in D7 pretty much just the D6 Services 3.x module? If so is there anyone writing a ZEND module for Services 3 that i can help to test/dev instead of doing this all from scratch? If they are both the same then developing a single module would satisfy both D6 and D7.

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: