<em id="hanht"></em>

    <dd id="hanht"></dd>

    <em id="hanht"><acronym id="hanht"></acronym></em>
    
    <button id="hanht"></button>
    <rp id="hanht"><object id="hanht"><blockquote id="hanht"></blockquote></object></rp><em id="hanht"></em>

    首頁 > 設計 > WEB開發 > 正文

    21.4.調用Flash Remoting方法

    2023-08-14 18:53:56
    字體:
    來源:轉載
    供稿:網友
    問題
    我想調用Flash Remoting 方法
    解決辦法
    使用NetConnection 對象連接Flash Remoting網關并用call( ) 方法調用方法
    討論
    Flex和Flash都有ActionScript APIs 來調用Flash Remoting 方法,不過這一節將討論用最底層的解決辦法。

    所有Flash Remoting 方法都基于flash.net.NetConnection 類,首先要創建NetConnection 對象:
    +展開
    -ActionScript
    var connection:NetConnection = new NetConnection( );

    下一步調用connect( )方法,傳遞進Flash Remoting網關的URL,例如:
    +展開
    -ActionScript
    connection.connect("http://localhost:8500/flashservices/gateway/");

    下面的代碼連接AMFPHP Flash Remoting 網關:
    +展開
    -ActionScript
    connection.connect("http://www.rightactionscript.com/flashremoting/gateway.php");

    connect( ) 方法并不會立即連接網關URL,如果URL不合法或服務器發生異常,都不會收到錯誤直到真正調用方法之后。

    下一步就是用NetConnection對象的call( )方法調用Flash Remoting方法,call( )方法需要兩個參數,第一個參數指定方法名稱和路徑,第二個參數指定響應處理函數,如果不需要處理函數,可直接設為null。

    第一個參數用點分隔符格式的路徑:
    package.ServiceObject.method
    如果用ColdFusion 組件(CFC),可訪問http://localhost:8500/com/oreilly/as3cb/Example.cfc, 定義的
    方法叫test( ) :
    +展開
    -ActionScript
    connection.call("com.oreilly.as3cb.Example.test"null);

    可以繼續在后面添加參數,例如test( ) 方法接收一個數字和字符串作為參數,可這樣寫:
    +展開
    -ActionScript
    connection.call("com.oreilly.as3cb.Example.test"null, 15, "abcd");
    發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表