« Pipe Demo: Mortgage App - AMFPHP Class Mapping Primer [1.9 beta] »

AMFPHP Complex Classes - Yeah I knew that

19 June 2008

Just blew half an hour tracking down something I *knew* I’d done before. Thought I’d post here for future ‘lapses.’

To return a typed object from PHP to the flashplayer the process is simple, declare a variable called $_expicitType in your PHP class
e.g.
class SummaryVO
{
var $_explicitType = "com.dl.SummaryVO";
$standards = array();
$levels = array()
}

In your corresponding ActionScript class use the RemoteClass metadata tag

package com.dl
{
[RemoteClass(alias="com.dl.SummaryVO")]
public class SummaryVO
{
public var standards:Array;
public var levels:Array;
}
}

Note the values for $_explicitType and alias are arbitrary, they can be what ever you’d like, as long as their the same in AS and PHP (provided your only conerned with PHP=>AS mapping).

Okay, so what happens when you have ‘complex classes’ you’d like to return? Complex meaning a class who’s members are made up of other ‘custom’ class instances.

Let’s say, for example, that in our later code example ’standards’ was an array of ‘StandardVO.’ The problem I ran into was that I was getting a typed ‘SummaryVO’ back from AMFPHP, however my class members were not typed, just generic objects. I checked and I had taken the necessary steps to use strongly typed SummaryVO and StandardVO classes, yet the StandardVO was coming back as a plain old Object.

We’ll it turned out in my development flurry I hadn’t used a reference to the ‘StandardVO’ class yet!! Simply declaring an instance of StandardVO did the trick (i.e. var placeHolder:StandardVO). You could also you the includes class […] compiler option.

Moral of the story, be sure the complier includes a reference to any class you want strongly typed from your RPCs.


Leave a reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

cheap generic kamagra kamagra uk viagra! Discount Viagra generic viagra levitra and cialis pills! "));