Example name: Mapping client and server-side objects between Flex and PHP
Description: The example demonstrates the following:
  • Usage of the flash.net.registerClassAlias API as well as the RemoteObject class attribute. Both approaches establish a mapping between server- and client-side value object
  • Server-side class uses Application scope, so only one instance of the class will be created for all connected clients
Client-side code: Browse  Download
Server-side code: Browse  Download
Run example:
Key points:
  • The mapping between client and server class takes place in the init() method registered as the applications creationComplete handler:
    flash.net.registerClassAlias( "Weborb.Examples.PhoneBookRecord", PhoneBookEntryVO );
     
  • Client class PhoneBookEntryVO corresponds to the server class Weborb.Examples.PhoneBookRecord. The classes are shown below:
     
    Client class Server class
    package PhoneBook
    {
      [RemoteClass(alias="Weborb.Examples.PhoneBookRecord")]
      public class PhoneBookEntryVO
      {
        public var firstName:String;
        public var lastName:String;
        public var phoneNumber:String;
      }
    }
    class PhoneBookRecord
    {
      var $firstName;
      var $lastName;
      var $phoneNumber;
    }

  • Notice how client class fields correspond to the server class property names
  • Notice the [RemoteObject] attribute in the client class definition. The attribute maps the class to the remote counter part. The attribute is commented out in the example's source, since an alternative approach is used.
Things to try:
  • Add an entry that starts with a number or any symbol that does not have a matching tab