as3 class map to php class
flash cs5 / amfphp1.9
description: 將as3的personVO class map 到setClassMappingsPath入面的Person class

amfphp1.9/services/
     SendObject.php
amfphp1.9/services/vo
    Person.php
htdocs/
    flash2php.fla
htdocs/org/flashremoting/
    PersonVO.as

 

gateway.php
 

  1. $gateway->setClassPath($servicesPath); 
  2. //$servicesPath在global.php define 為 services/ 
  3. $gateway->setClassMappingsPath($voPath); 
  4. //$voPath在global.php define 為 services/vo/ 
  5. $gateway->setCharsetHandler( "iconv", "utf-8", "gbk" ); 

flash2php.fla

  1. import org.flashremoting.PersonVO; 
  2.  
  3. registerClassAlias("Person", PersonVO); 
  4.  
  5. var nc:NetConnection = new NetConnection(); 
  6.  
  7. nc.objectEncoding=ObjectEncoding.AMF3; 
  8. nc.connect('http://localhost/amfphp1.9/gateway.php'); 
  9. var responder:Responder=new Responder(onResult,onError); 
  10.  
  11. nc.call('SendObject.sendVO', responder ,new PersonVO()); 
  12. function onResult(re:Object):void { 
  13.     var personData:PersonVO = PersonVO(re); 
  14.     trace(String(personData.name)); 
  15. function onError(err:Object):void { 
  16.     trace("接收错误"); 

PersonVO.as

  1. package org.flashremoting 
  2.    public class PersonVO { 
  3.         public var name:String ="Sharon"
  4.     public function printDetails():void{ 
  5.         trace("name======="+this.name);} 

Person.php
 

  1. <?php 
  2. class Person 
  3.  public $name="abc"
  4. }?> 

SendObject.php
 

  1. <?php 
  2. class SendObject 
  3. {   
  4.    function sendVO($aa
  5.     { 
  6.       $aa->name = "modified"
  7.       return $aa
  8.    } 
  9. ?>