天天看點

flash與背景資料交換方法整理2-Flash Remting篇

二、Flash Remoting

  Flash Remoting這種資料接口是四個之中效率最高的!

  其優點:

    1.支援資料類型比較多(Converting from application server data types to ActionScript);

    2.傳遞資料量比較大;

    3.運作效率是現有幾個當中最高的;

    4.對各種背景的支援也比較好;

    5.其還有調試子產品(NetConnection Debugger)

  其缺點:

    1.需要flash端裝Flash Remoting MX Components(這個是免費提供的);

    2.需要背景服務端裝相應版本的Flash Remoting子產品才可以使用,MM提供的子產品有j2ee和.net兩個版本是要收費的,好在網上還有兩個開源的(OpenAMF,AMFPHP);

    3.好像Remoting對虛拟主機的支援不太好(可以去google搜尋一下,有沒有解決方法).

================================================================

  Flash端代碼說明:(我這裡用as1.0版本為例,其他版本到MM站查找)

================================================================

  //加載Remoting Component代碼,這個是必須的;

  #include "NetServices.as"

  //加載Remoting 調試子產品代碼,這個是可選擇的,用NetConnection Debugger檢視調試資訊;

  #include "NetDebug.as"

  if (inited == null){ 

    inited = true;

    //設定預設網關;

    NetServices.setDefaultGatewayUrl("

[url=:8500/flashservices/gateway]:8500/flashservices/gateway[/url]

");

    //建立網關連接配接;

    gateway_conn = NetServices.createGatewayConnection();

    //擷取一個服務;

    myService = gateway_conn.getService("myservice", this);

  }

  //定義調用方法的函數;

  function getString(name){

    //調用Remoting的getString方法;

    myService.getString(name);

  }

  //定義傳回結果的函數;

  function getString_Result(result){

    //result就為傳回的結果;

    trace(result);

  }

  //定義傳回狀态的函數,此為可選的;

  function getString_Status(error){

    trace("getString_Status");

    trace(error.code);

    trace(error.description);

    trace(error.details);

  }

  //調用函數;

  getString("kinglong");

================================================================

  服務端方法定義(我這裡以Coldfusion Component為例,其他版本請參考相應的資料)

================================================================

另附上Flash Remoting的線上幫助檔案(Flash Remoting LiveDocs),MM網站上的Remoting相關的資料.

    1.LoadVars(XML)

    2.Flash Remoting

    3.Webservice

    4.XMLSocket

本文轉自:http://www.5uflash.com/flashjiaocheng/Flashyuweb/2081.html

繼續閱讀