Tag Archive for 'AS 3 ByteArray'

My Adobe Flex / PHP Client / Server Articles on O’Reilly InsideRIA

Following are my six articles on DeveloperRIA on related to developing Adobe Flex clients using Adobe Flash Builder, which resource data from PHP Web application servers.

Using Flex 4 Clients with the PHP Zend Framework Server

Flex 4 / PHP Data-Centric Photo Transfers

Flex 4 / PHP Data-Centric Solutions

Photo Gallery Mate Framework, With Photo Caching

Processing AMF 3 PHP Server Object Arrays on the Flex Client Using Object Relational Mapping

AMF3 PHP Server Objects to Flex Client Object Relational Mapping

Note: if you plan to use the example code in my article Photo Gallery Maté Framework, With Photo Caching, then also be sure to read my article Flex 4 / PHP Data-Centric Photo Transfers.



DevelopRIA: Photo Gallery Maté Framework, With Photo Caching Article

My article titled Photo Gallery Maté Framework, With Photo Caching has just been published on  the DevelopRIA blog.

I have have been developing Adobe Flex-based RIA applications for nearly three years. My prominent need has been for capable RIA photo galleries. I observed over time that most Adobe Flex-based example photo galleries resourced photos—either locally or remotely—from photo files stashed in folders or folder hierarchy. There are better ways using Adobe Flex Builder to create RIA clients, what are driven from a photo database repository residing on a remote PHP Web application server.

The article’s example photo gallery is a worthwhile visit to better appreciate what my DevelopRIA article is all about. And if you mouse right-click in your Web browser, you can view the source code for this photo gallery. Visit the DevelopRIA article for the details of how this photo gallery client / server solution works along with a detailed analysis of core software code.

Noteworthy to this article is my adjunct blog note titled Adobe AMF 3 Transfer of Photo Data From a PHP Application Server To a Adobe Flex Client. This article expands on  issues with PHP string data types when when transferring photos from the Web application server to the Flex client.

If you need additional basic information related to developing and deploying Flex Builder to PHP application server, client / sever remoting, then see my two earlier InsideRIA blog articles on these topics:

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’