Data-driven Flash Development with AMFPHP David Knape
Who am I? PHP Programmer since 1998 Flash Programmer at Second Story Independent Contractor, Consultant Recent Work: – – – –
What is Flash Remoting? Toolkit for client/server data exchange and remote method invocation over HTTP. “Web services” with AMF instead of SOAP –Binary Format == Less Bandwidth than XML –Flash Player decodes it quicker than XML –AMF3 is the new Format used by default in Flex 2 Allows Flash and Server to speak the same language. Free and open-source PHP implementations: –AMFPHP – –WebOrb –
Why not use SOAP? SOAP has larger payloads SOAP requires more CPU processing Memory Leak with Flash Web Services API Remoting just works better in the Flash player Benchmarks: ing_benchmark.htm
Getting Started with AMFPHP Unzip amfphp package into server root Create new php class in amfphp/services: <?php class TestService { remote function sayHello( $name ) { return "Hello, ".$name; } } ?> Create Method Table using browser and include in constructor: function TestService(){ include("TestService.methodTable.php"); } Test the Service -
RecordSet Object that represents a query result AMFPHP automatically creates recordsets from the result of a database query Flash Remoting classes includes mx.remoting.RecordSet which implements the DataProvider API Flash Components can use recordsets as data providers
Paged Recordsets Results sent in batches as needed Allows flash components to show lengthy lists without loading everything at once Example:
ADODB for PHP Database abstraction layer for PHP To use ADODB with AMFPHP: 1. Add adapter mapping for DB-specific AdoRecordset classname 2. Set fetch mode to ‘fetch_num’ $gateway->addAdapterMapping('adorecordset_mysql', 'adodb'); $DbConnection->SetFetchMode( ADODB_FETCH_NUM );
Sample App: Gallery Site MySQL Database holds items and references to image files PHP class method queries database and returns the results AMFPHP exposes the PHP Class as a “Service” Actionscript calls the service method via the AMFPHP Gateway
Gallery Admin Tool Admin tool built with CakePHP – Images accessed with phpThumb – see
Gallery ActionScript GalleryApp – Application Root MovieClip ModelLocator – Application Data / State GalleryService – our service class Clips: Menu – loads service and lays out menu items MenuItem – triggers selectedItem state change Content – loads image when state changes
FlashDevelop Free AS editor Code hinting MTASC compiling Code generation Overall improved workflow
Bumpslide Library Common Service interface and ServiceProxy State management with observable Model –Similar to AS3 ObjectProxy –Supports one-way data binding Utility classes – com.bumpslide.util See
References Remoting Components - oads/components/ oads/components/ Remoting Classes with MTASC - ing-remoting-running-in-mtasc/ AMFPHP - FlashDevelop – MTASC – WebOrb –