Flash + Drupal 7 using AMF Server (setup problems solved)

Seems like today it's very simple to get good comunication betwen flash (frontend) and drupal 7 (backend), good people had wrote just great API to make your work as simple as possible... but there are spots even in the sun. Here are my steps to make them workin' on D7 + Flex SDK 4.5.

What you need to have already:

  • Drupal 7 installed;
  • Flex SDK 4.5 and some IDE (free FlashDevelop can help).

Steps to install AMF3 service on your Drupal 7 (D7)

  • Install Services module (http://drupal.org/project/services);
  • Place amfserver module to your modules dir (http://drupal.org/project/amfserver);
  • Download Zend PHP framework and place it to /sites/all/libraries/zend (amfserver module will give you the link to zend lib if you'll try to enable it).
  • Enable 'amfserver';
  • Add AMFService:
    • Go to (your_site)/admin/structure/services/add
    • Type any name, select 'amfserver' from combobox;
    • Type endpoint path. This will be url to your service, for example: 'api/amf';
    • Check 'Debug mode enabled' and 'Session authentication';
    • Click 'Save';
    • Visit (your_site)/(endpoint_path) and you must see message from AMF (for our example it will be: site.com/api/amf).
  • Bug fixes current (by 04.12.11) verisons that we need to make:
    This fixes only to current versions, because there are reports and issues about that bugs, so for newer versions you do NOT need do such code hacking.
    • File sites\all\libraries\zend\amf\response\http.php, @line59 change "$ssl = $_SERVER['HTTPS'];" to "$ssl = isset($_SERVER['HTTPS']);".
    • File sites\all\modules\services\plugins\export_ui\services_ctools_export_ui.inc, find "$endpoint->debug = $form_state['values']['debug'];" and ADD below "$endpoint->server_settings = array($endpoint->server => array());"

Make flash to call Drupal service methods and load data

I've used DrupalProxy.as by Rolf Vreijdenberger, Thomas Brekelmans from dpdk.nl lib (as advice on amfserver module page), it's very userfull solution with examples and good in-source documentation... but there is error in current version too (on 04.12.11) on @line256 find "if (data.description != null) {" and replace it with "if ((data as Object).hasOwnProperty('description')) {"

Done!

So now you are done. And can finally invoke service method calls to Drupal from Flesh application (or flex).