AMFPHP+FLEX簡單應用

來源:互聯網
上載者:User

首先到AMFPHP官方去下載安裝包:http://www.amfphp.org/

下載完後,解壓檔案並把檔案放到伺服器下。

http://localhost/amfphp/gateway.php
瀏覽會看到

 

amfphp and this gateway are installed correctly. You may now connect to this gateway from Flash.

Note:
If you're reading an old tutorial, it will tell you that you should see
a download window instead of this message. This confused people so this
is the new behaviour starting from amfphp 1.2.

View the amfphp documentation

Load the service browser

 

顯示上面資訊,說明安裝成功。所有的PHP檔案,都要放到amfphp/services/下。

例如建立個MyPHP/HelloWord.php檔案:

<?php<br />class HelloWord{<br /> function HelloWord(){}<br /> function sayHello(){<br /> return 'Hello Word';<br /> }<br />}<br />?>

在http://localhost/amfphp/browser/
中會看到你剛建立的檔案,並測試該檔案是否正確。

 

建立FLEX項目:

建立項目時,要確認是否加入了RPC.SWF模組,並在項目屬性的Flex Complier裡加入 -services "services-config.xml"

並在src下建立services-config.xml檔案

<?xml version="1.0" encoding="UTF-8"?><br /><services-config><br /><services><br /><service id="amfphp-flashremoting-service" class="flex.messaging.services.RemotingService"<br /> messageTypes="flex.messaging.messages.RemotingMessage"><br /><destination id="amfphp"><br /><channels><br /><channel ref="my-amfphp"/><br /></channels><br /><properties><br /><source>*</source><br /></properties><br /></destination><br /></service><br /></services><br /><channels><br /><channel-definition id="my-amfphp" class="mx.messaging.channels.AMFChannel"><br /><endpoint uri="http://localhost/amfphp/gateway.php" class="flex.messaging.endpoints.AMFEndpoint"/><br /></channel-definition><br /></channels><br /></services-config>

其中<channel ref="my-amfphp"/>的ref必須要於channel-definition 的id一樣。

 

建立mxml檔案,調用RemoteObject

<mx:RemoteObject id="myService" destination="amfphp"    showBusyCursor="false" source="MyPHP.HelloWord" fault="onFault(event)"><br /> <mx:method name="sayHello" result="onResult(event)"/><br /></mx:RemoteObject>

  • destination
    屬性需要與services-config.xml的配置<destination id="amfphp">相對應
  • source
    屬性會找到amfphp/services/MyPHP/HelloWord.php檔案,也就是剛才所建立的PHP檔案。
  • 節點<mx:method/>定義調用的方法:name="sayHello"為HelloWord裡的sayHello方法,直接對應。             result接受傳回值。

private function onResult(evt:ResultEvent):void{<br /> trace(evt.result.toString());<br />}

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.