Flash Remoting and P..

Download Report

Transcript Flash Remoting and P..

Data-driven Flash
Development with AMFPHP
David Knape
http://bumpslide.com/
Who am I?
•
•
•
•
PHP Programmer since 1998
Flash Programmer at Second Story
Independent Contractor, Consultant
Recent Work:
–
–
–
–
http://designarchives.aiga.org/
http://arago.si.edu/
http://explorer.monticello.org/
http://bumpslide.com/
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 – http://amfphp.org/
– WebOrb – http://themidnightcoders.com/
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:
http://www.themidnightcoders.com/articles/soap_vs_flash_remot
ing_benchmark.htm
Getting Started with AMFPHP
• Unzip amfphp package into server root
• Create new php class in amfphp/services:
<?php
class TestService {
// @access 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 - http://amfphpdemo/amfphp/browser/
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:
http://testbed/northwind/swf/
ADODB for PHP
Database abstraction layer for PHP
http://adodb.sourceforge.net/
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
– http://cakephp.org/
• Images accessed with phpThumb
– http://phpthumb.sourceforge.net/
see http://amfphpdemo/cake/
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 http://bumpslide.sourceforge.net/
References
• Remoting Components http://www.adobe.com/products/flashremoting/downl
oads/components/
• Remoting Classes with MTASC http://www.5etdemi.com/blog/archives/2006/01/getti
ng-remoting-running-in-mtasc/
• AMFPHP - http://amfphp.org/
• FlashDevelop – http://flashdevelop.org/
• MTASC – http://mtasc.org/
• WebOrb – http://themidnightcoders.com/weborb/