Note: You are currently viewing documentation for Moodle 3.4. Up-to-date documentation for the latest stable version of Moodle is likely available here: AMF Moodle.

AMF Moodle

From MoodleDocs

What is AMFPHP?

AMFPHP is a widely used open source remoting server that allows Flash and Flex client-side applications to call PHP methods directly, as if they were native Flash/Flex ActionScript methods. It is fast and lightweight and presents a very efficient method of communicating with PHP and databases. AMFPHP preserves the following data types between ActionScript and PHP:

  • int
  • Number
  • String
  • Array
  • mysql_result/Recordset

Note: Please add to this list if you have successfully tested data types using AMFPHP 1.9.beta+ and ActionScript 3.0.

AMFPHP automatically converts data types between ActionScript and PHP to their native equivalents. For example, it can convert a PHP array into and ActionScript array or a PHP resource, such as a mysql_result into an Actionscript Recordset.

What is AMF Moodle?

AMF Moodle is a new project (9th October 2008) which aims to integrate Flash and Flex with Moodle's API. The aim is to build a library of services that Flash and Flex developers can use to create secure client-side applications that can interact with Moodle. The first step will be to create a Moodle module that facilitates deploying custom made, generic Flash and Flex e-learning interactions and recording user interaction results in the Moodle gradebook.

The project's participants at the moment are: Matt Bury, Jamie Pratt and Marcus Potter. You can find the project home page at code.google.com.

Installing AMFPHP in Moodle

  • Download the latest version of AMFPHP, currently version 1.9.beta (SourceForge repository).
  • Unzip the file and find the directory amfphp.
  • Upload the amfphp directory to ***MOODLEROOT***/lib/
  • That's it!

Please note: AMFPHP requires PHP 5 to run. Many servers run both PHP 4 and 5, but have them set to run PHP 4 by default. If you experience problems, you may have to change the default PHP version in the ***MOODLEROOT***/lib/amfphp/ directory with an .htaccess file. The following is an example only. Please check that it is correct for your server configuration. If you have a hosted server, they'll probably have an example in their help files. For example:

  • Find the AMFPHP .htaccess file at ***MOODLEROOT***/lib/amfphp/.htaccess
  • Open it with a text editor. You'll see:
#If you're working with a server which doesn't seem to display errors and you don't 
#have access to httpd.conf and you have a good reason to develop remotely instead of
#locally, you may have luck with uploading this configuration file to the server

php_flag display_errors on
php_flag display_startup_errors on
php_value error_reporting 2047
  • Add another line of code to change the default PHP version setting for the amfphp directory:
#If you're working with a server which doesn't seem to display errors and you don't 
#have access to httpd.conf and you have a good reason to develop remotely instead of
#locally, you may have luck with uploading this configuration file to the server

php_flag display_errors on
php_flag display_startup_errors on
php_value error_reporting 2047

SetEnv DEFAULT_PHP_VERSION 5

Testing AMFPHP in Moodle

TODO: A quick simple PHP script to return user login info in PHP only (UserName.php)

Testing AMFPHP in Flash

Please note: Flash CS3 and Flex come with the necessary classes for using AMFPHP already installed. It is not necessary to install any new classes!

TODO: Call the UserName.php service from ActionScript.

AMF Moodle Service Library

TODO: We'll probably need a new page to list the services, what they do, and their methods, parameters and returned values.

From Matt: I think any new services provided for the AMF Moodle library should be object oriented and in PHP 5, using public and private namespaces. Let's follow best coding practices from the start! :)

Useful Links

AMFPHP

  • AMFPHP home page not available! (They've lost amfphp.org)
  • AMFPHP code repository SourceForge.net

AMFPHP Tutorials

Sir Lee Brimelow's excellent video tutorials:

Learn how to install AMFPHP and create a simple service that sends email.

In this tutorial he shows you how to directly return database records to Flash using AMFPHP.


AMF Moodle