Monthly Archive for December, 2009

Adobe AMF 3 Transfer of Photo Data From a PHP Application Server To a Adobe Flex Client

Author’s Update, June 1, 2010

This article describes how and why you need to modify the WebORB for PHP internal PHP code so that you can transfer photos from the PHP server to the Flex client, arriving as ActionScript 3 ByteArray data type. This internal PHP code modifications, described later in this article are no longer necessary. I recently identified a new way perform this photo data transfer by replacing the WebORB for PHP application server with Zend’s Zend Framework application server. Zend Framework supports photo data transfers without requiring internal code modification of PHP code within the framework. See my DevelopRIA article Flex 4 / PHP Data-Centric Photo Transfers for details on how to replace WebORB for PHP with Zend Framework.


Transferring photos from the PHP server to the Flex client via AMF 3 RemoteObject data streams is currently one of my favorite RIA topics. That’s because it took me more than a few days to figure out why I was able to display my photos when they were on the PHP server, but I could no longer display them by the time they were received by my Flex client. I’m anxious to share what I know about this in the hope that others do not have to go through what I did to get this working properly. The subtleties of what happens during the server-to-client photo data transfer are enough to drive you up the wall.

Here’s the scenario, what you’ll require and the specific solution that helped me.

In my SQGallery application article in DevelopRIA, we were discussing a Flex-based photo rendering RIA named SQGallery that pulls the photos from a MySQL database with Action Message Format (AMF3) Messaging through the WebORB for PHP application server. The dilemma is that the PHP data types are somewhat restricted in what’s available to meet our needs. Principally, the PHP data types are four scalar types: boolean, integer, float (floating-point number, a.k.a. ‘double’) and string; two compound types: array and object; and finally two special types: resource and NULL.

When the WebORB PHP application server loads photo data — effectively an array of bytes — from the SQPhoto MySQL database, PHP insists on typing photos as a string data type. Ah, I thought, all sounds well and good. I will simply return the photo PHP string photo byte array to the Flex client, receiving the photo data as an ActionScript 3 (AS3) String object. Then I will cast the String AS3 object to a ByteArray AS3 object so that the photo can be rendered and displayed using the Loader AS3 class.

The above is a great idea, but it did not work. I wondered why. After all, PHP strings are AS3 Strings … or are they? The AS3 String objects are formatted UTF-8, which means single-byte strings — the same as PHP server-side strings, right? You are wrong by 100%. In ActionScript, if the eighth bit (bit 7) of any byte is set (1), then the UTF-8 single byte is extended to a two-byte UTF-8 sequence. And guess what? Many of the photo string (array of bytes) have the eighth bit set. Talk about messing the photo content up! No wonder photos won’t display in the SQGallery Flex client.

Continue reading ‘Adobe AMF 3 Transfer of Photo Data From a PHP Application Server To a Adobe Flex Client’

Welcome to Pete’s Blog at Seaquest Software

Stay abreast for details on Adobe Flex and AIR based RIA (Rich Internet Application) development about photo gallery client examples.