Note that the local class name associative key (‘myclass’ above) must be in lowercase with the current release of AMFPHP.
Rely on the reflection class (PHP 5+)
If your install of PHP has the ReflectionAPI you can let AMFPHP do the work *for* you. I found a few cavets using this approach on servers who’s OS uses backslashes natively. If this is the case, AMFPHP will only send the name of the class and not include any package info. There are two simple code changes you can make in AMFPHP to get around this, just drop me a line if your interested (hopefully they’ll be commited in the next release of AMFPHP).
Make sure your actionscript project contains a reference to the class. See my previous post for more info.
Sending Strongly Typed Objects from ActionScript to PHP via AMFPHP
Rely on the class having been registed in ActionScript with the server’s correct package [directory] structure (relative to AMFPHP’s VO base path $GLOBALS[‘amfphp’][‘customMappingsPath’]). If this is the case you, your all set.
Note: If you haven’t already you’ll need to make sure $voPath is pointing to the correct directory in AMFPHPs global.php
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
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.
I threw this together off the cuff, so don’t expect too much 🙂
The app (10K) simply loads 6 modules dynamically, 3 “RedTint” modules and 3 “GreenTint” modules (4k each). The app sends a notification every second containing a random color. The loaded modules pick up on this notification and display the color – each with their corresponding tint.
Keep a close eye on Cliff’s Pipe utility as these classes may soon be obsolete 🙂 Until that time, I hope you might find this useful – if you do, drop me a line and let me know.
I’ve got some time between projects if anyone is looking for some RIA development…