Flex 3 and Zend_Amf Class Mapping Hint
June 29, 2009
For my latest little Flex project, I used Zend Amf instead of amfphp for remoting. I had no trouble getting started with Zend Amf since I’m familiar with amfphp and there are good resources available on the web ( e.g. Zend Amf Wiki and Flex and PHP: remoting with Zend AMF ).
However, one thing really bugged me. Not all of the class mappings worked as expected. For some of the classes I got general objects back in my Flex application instead of the typed objects. I checked forth and back and couldn’t find any bug in my code. So I checked the web and found a solution to my problem. First of all, I recommend you to watch the screencast created by the lead developer of Zend Amf (Wade Arnold), which shows the different possiblities to set up the class mapping.
That brought me to Charles, with which I could check that the desired class type is really returned by php remote service.
As this was the case, I searched the web for some more information about the class mapping in Flex. Finally I came across this forum thread offering some ideas to make the class mapping work.
This answer in the thread helped in my situation.
I added the registration to the creationComplete handler function in my application as follow:
/**
* Creation complete handler
*/
public function build() {
// Register remote class mapping
registerClassAlias( "vo.PublicationVO", PublicationVO);
registerClassAlias( "vo.MonthlyHitsVO", MonthlyHitsVO);
registerClassAlias( "vo.DailyHits", DailyHitsVO);
registerClassAlias( "vo.PageHitsVO", PageHitsVO);
}
… and all the class mappings worked like a charm.
The dcoumentation for the registerClassAlias(aliasName:String, classObject:Class):void method can be found here.
In my case, the problem was, that I didn’t used an instance of some of the classes in the Flex app yet, so the class was not compiled into the SWF.
August 16, 2009 at 5:14 pm
Thank you for posting this. Whilst I use Eclipse/Texlipse without problems on Linux/Windows, getting the previewer to work correctly without popping up multiple instances is a hassle. Your solution works perfectly.
August 17, 2009 at 8:50 am
Thank you for the kind comment …