Intro examples for Zend Amf
December 18th, 2008
In a constant balance between new features and documentation I am releasing the first ‘examples’ today. This is a long way from being full blown best practices or tuturials but I hope it is a starting point. In this first release I have added a Flash and Flex Hello World example and a class mapping example for Flex that shows how to get ContactVO’s from the server and bind them in Flex. Please let me know what you want next.


Hi Wade! Thanks for putting together the examples! Your work on Zend AMF is very much appreciated.
I’m wondering though why the Zend AMF server setup is always done directly in the bootstrap file. I guess the only reason is that it keeps the learning curve low for developers who are not familiar with ZF. In a reald world scenario though you most probably want to make use of other ZF features in your service classes (Zend_Config, Zend_Db, Zend_Pdf, etc.). That’s why I think it makes more sense to set up the AMF gateway inside a regular Zend controller, and keep the bootstrap file free from any AMF server-related code. Also, if the AMF server resides inside a controller you are free to add other controllers that, for example, provide HTML interfaces to the same core application. This way it’s very easy to build hybrid applications with both Flex/Flash and HTML interfaces.
I blogged on my Zend controller approach (http://blog.log2e.com/2008/12/14/utilizing-the-zend-amf-server-inside-a-zend-controller/), but I’d like to kow what you consider best practice for Flex/Flash applications that are supposed to exploit more ZF features than just Zend AMF.
@Stefan, thanks for pointing this out.
@Wade: How can you set this up for flash player 9, as3 only project (in flex). Basically i am looking for smallest filesize solution and it should be working on fp9.
Wade,
Thank you again for your work on Zend_Amf.
I’ve worked with another Amf framework and for me Zend_Amf is the best choice so I thought I’d let you know, I just created a simple two part tutorial about building a better Login using Flex, Zend_Amf, Zend_Auth, and Zend_Acl, complete with the Flex and PHP source code.
The tutorial is on my website http://www.keithcraigo.com
Has this been answered at all somewhere?
I just finished my post how to setup Zend_Amf with full Zend Framework, here it is http://www.riaspace.net/2009/01/zend_amf-with-full-zend-framework/
p.
Brand new to Zend and experimenting with it in Flash.
I am able to retrieve records from my DB, but am getting this error message when I try to create a new record.
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion
at dbtest_fla::MainTimeline/frame1()
I’d really appreciate any help.
Flash:
var nc:NetConnection = new NetConnection();
nc.connect(“http://www.mywebsite.com”);
var res:Responder;
but.addEventListener(MouseEvent.MOUSE_DOWN, sendEvents);
but.buttonMode = true;
function sendEvents(e:MouseEvent):void
{
nc.call(“events.createEvent”, res, (ev_title.text, ev_date.text, ev_type.text, ev_area.text));
}
PHP:
function createEvent($ev_title, $ev_date, $ev_type, $ev_area)
{
$sql = “INSERT INTO events VALUES ( ” .
“NULL, ” .
“‘” . $ev_title . “‘, ” .
“‘” . $ev_date . “‘, ” .
“‘” . $ev_type . “‘, ” .
“‘” . $ev_area . “‘ )”;
$result = mysql_query( $sql );
$id = mysql_insert_id();
$event = new Event();
$event -> id = $ev_id;
$event -> ev_title = $ev_title;
$event -> ev_date = $ev_date;
$event -> ev_type = $ev_type;
$event -> ev_area = $ev_area;
return $event;
}
Hi Wade,
Could you put up an example that demonstrates saving and sending an entire value object up to the server? In particular a rather complicated object with a complicated structure including properties that are ArrayCollections and some properties that are other objects.
Here is an example
Currently I have something similar to this in my code
var myObject:MyPerson = MyPerson();
myObject.name // String
myObject.address // String
myObject.listofFriends // Arraycollection of MyPerson objects
var remoteObject:RemoteObject;
remoteObject = new RemoteObject();
remoteObject.destination = “zend”;
remoteObject.source = “MyService”;
remoteObject.endpoint = AMF_ENDPOINT_URL;
remoteObject.saveMyObject.addEventListener(ResultEvent.RESULT, _handleSaveObjectResult);
remoteObject.saveMyObject.addEventListener(FaultEvent.FAULT, _handleSaveObjectFault);
remoteObject.saveMyObject(
myObject.name,
myObject.address,
myObject.listofFriends
);
The problem is that in my service call I am having to break the object down into simple parts and send those to the PHP server as particular parameters composed of more primitive types that PHP seems to know how to deal with. Stings, numbers, arrays, etc.
I ideally I would like to simplify the code on the flex side and just pass an entire complex object as a parameter to the remote service. e.g. take the above and reduce it down to something like this:
var remoteObject:RemoteObject;
remoteObject = new RemoteObject();
remoteObject.destination = “zend”;
remoteObject.source = “MyService”;
remoteObject.endpoint = AMF_ENDPOINT_URL;
remoteObject.saveMyObject.addEventListener(ResultEvent.RESULT, _handleSaveObjectResult);
remoteObject.saveMyObject.addEventListener(FaultEvent.FAULT, _handleSaveObjectFault);
remoteObject.saveMyObject( myObject );
The problem is when the PHP side receives “myObject” it doesn’t quite know what to do with it. And I am a little lost on how to pass a complex object as a parameter to the remote service.
Some sort of tutorial addressing this would be helpful.
In particular something that introduces a little bit of recursion as well would be helpful to review. e.g. objects that contain other objects or additional instances of itself.
Thanks.