Workingn with AMF
I want to set up a more secure process than a current ActionScript POST/GET service querying. To do that I started looking at AMF.
Action Message Format(AMF) is a binary file format representing a serialized ActionScript object. The AMF file type is used throughout the Flash Player for data storage and data exchange. For example in the Flash Player AMF is used in SharedObjects, RemoteObjects, LocalConnection, ByteArray, RTMP, and all RPC operations. Some of the benefits of AMF include:
- File Size – AMF objects are very small and are compressed using zlib.
- Fast Serialization/ Deserialization – AMF is transformed using native C code in the Flash Player making it very fast. The AMF format was designed to serialize and deserialize quickly under low memory and slower CPU conditions making it perfect for the web. AMF data is parsed directly into objects, meaning there is no lag for interpretation or parsing of AMF making the creation of objects complete in a single pass.
- Native Types and Custom classes supported – You can serialize any object in Flash Player with the only exception being a displayObject.you can also map serialized objects back to custom class instanced provided the custom class is in the Flash Player when the AMF object is deserialized.
AMF existed in ActionScript 2 and was just called AMF as of ActionScript 3 the AMF protocol has been updated and is referred to as AMF3. For historical reasons the original AMF format is now referred to as AMF0. One of the main upgrades to AMF3 is that the object is now zlib compressed for faster transfer do to the smaller file size and the additional of data types that were released with ActionScript 3.
The two alternative frameworks that I am looking at are AMFPHP and Zend_AMF.
AMFPHP + Flex 3 = Error [unable to open 'services-config.xml']
While trying to configure the AMFPHP set up with the Flex 3 framework I ran in to a problem while setting up the services-config.xml.
I’ve created the file in the root directory and specified in the Flex Compiler [Additional compiler arguments] the following string -locale en_US -services “services-config.xml”.
As soon as I clicked OK an error popped up with a message unable to open ’services-config.xml’. After trying varying things I was able to figure out that the problem was with the location of the file. Simply placing the file at the root of the directory wasn’t the right location. I needed to put the file in the same directory as the main MXML executable – after that the program worked as expected.
Cyrilic integration of Flex and PHP
A recent project involved integration between a PHP content management tool like Joomla and Adobe Flex 2. I wrote a PHP script that parsed a MySQL database creating an XML structure that was then picked up by a HTTPService in a Flex application.
The information in the database was stored in Cyrillic format, hence when ever I was loading the data in to the SWF compiled file the end result was a collection of garbage data. Setting the actuall HTML to Windows-1251 encoding did not help the situation.
My following approach was to locate a native functionality within the Flex architecture to mediate the situation. Unforchunately I wasn’t successful in aquiring sattisfying examples to solve the problem. For that matter it became sadly obvious that I haven’t seen any flash pages using non/english alphabet [either I haven't been checking international sites that much or Adobe Flex isn't widely used overseas] .
My third approach was to look at the actual php code that was generating the XML structure. I’ve discovered a useful function mb_convert_encoding that eventually solved my problems. Using a simple snippet of code:
mb_convert_encoding($string_to_convert,'UTF-8','Windows-1251');
I was able to convert the data from UTF-8 in to Windows-1251 which allowed me to display the desired Cyrillic characters.