杨庆荣的博客

工作之余接单:公司产品展示网站建设、电商网站建设、小程序、app开发。+86 13714715608

amfphp2.0 入门demo

点击 2285    创建时间 2011-11-26 22:55:15

.mxml文件

 <?xml version="1.0" encoding="utf-8"?> 
 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
 xmlns:s="library://ns.adobe.com/flex/spark" 
 backgroundColor="#001116" 
 xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" applicationComplete="application1_applicationCompleteHandler(event)"> 
 <fx:Declarations> 
 <!-- Place non-visual elements (e.g., services, value objects) here --> 
 </fx:Declarations> 

 <fx:Script> 
 <![CDATA[ 
 import mx.controls.Alert; 
 import mx.events.FlexEvent; 
 import mx.rpc.events.ResultEvent; 
 import mx.rpc.remoting.RemoteObject; 
 private var RO:RemoteObject; 

 protected function application1_applicationCompleteHandler(event:FlexEvent):void 
 { 
  RO = new RemoteObject; 
  RO.destination = "amfphpExamplesGateway"; 
  RO.endpoint = "http://127.0.0.18/amfphp/public/Php/"; 
  RO.addEventListener(ResultEvent.RESULT, showResult); 
  RO.source = "WudimeiService"; 
  RO.add( 233, 500 ); 
 } 

 private function showResult(event:ResultEvent):void{ 
  Alert.show("" + event.result); 
 } 

 ]]> 
 </fx:Script> 
 </s:Application>

WudimeiService.php


 <?php 
 class WudimeiService { 

 function add( $num1 , $num2 ) 
 { 
    return "result:". $num1 . "+" . $num2 . "=" . ( $num1 + $num2 ); 
 } 
}

如果php返回的是: return array( "msg" => "result:". $num1 . "+" . $num2 . "=" . ( $num1 + $num2 ) );

在flex中是这样显示的:Alert.show("" + event.result.msg );

可见flash把php中的数组看成对像来对待的。

很幸运,我把它当成数组也能通过:

 Alert.show("" + event.result["msg"] );

flex学得不好,老鸟请飘过,飘到南极吧……^_^

上一篇: 在eclipse PDT中使用PHP Source Plugin生成getter和setter方法。
下一篇: smarty 3.16 函数的使用