AMFPHPはじめの一歩
AMFPHPって、あまり日本語の情報が少ないですよね・・・。
もうちょっと盛り上げて行きたいです。
ってことで、ひとまずはじめの一歩。
このくらいエントリしている人は何人かいるけど・・・
/amfphp/services/Test.php
<?php class Test { var $methodTable; // コンストラクタ関数 public function Test() { $this->methodTable = array( "getMsg" => array( "description" => "Function getContents test", "access" => "remote", "arguments" => array("str") )); } // テスト用関数 public function getMsg($str) { return 'SendedMsg:'.$str; } } ?>
Flex側
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:s2="http://www.seasar.org/s2flex2/mxml" layout="absolute"> <s2:S2Flex2Service id="S2Services" gatewayUrl="http://localhost/work/PhpStudy/amfphp/gateway.php" destination="Test" result="test_onResult(event)" fault="test_onFault(event)" showBusyCursor="true" /> <mx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; import mx.rpc.events.FaultEvent; private function test_onResult(event:ResultEvent):void { result_text.text = event.result.toString(); } private function test_onFault(fault:FaultEvent):void { result_text.text = fault.fault.message; } private function clickHandler(evt:MouseEvent):void { S2Services.getMsg(msg_text.text); } ]]> </mx:Script> <mx:VBox width="569"> <mx:TextArea id="result_text" width="100%" height="300" /> <mx:TextInput id="msg_text" width="100%" height="20" /> <mx:Button label="test" click="clickHandler(event)" /> </mx:VBox> </mx:Application>