Warning: include() [function.include]: URL file-access is disabled in the server configuration in /virtual/innerchild/public_html/2008/06/26-022552.php on line 91

Warning: include(http://innerchild.jp/menubar.php) [function.include]: failed to open stream: no suitable wrapper could be found in /virtual/innerchild/public_html/2008/06/26-022552.php on line 91

Warning: include() [function.include]: Failed opening 'http://innerchild.jp/menubar.php' for inclusion (include_path='.:/usr/local/lib/php') in /virtual/innerchild/public_html/2008/06/26-022552.php on line 91
Index flash ActionScript 3.0 > Flash CS3 と amfphp 1.9 beta2 で Flash Remoting + クラスマッピング

<< Google Developer Day サポーターになると得する10のこと。 | Flash CS3 と amfphp 1.9 beta2 で Flash Remoting + クラスマッピング | 携帯を新しくしました、が。 >>


Flash CS3 と amfphp 1.9 beta2 で Flash Remoting + クラスマッピング 

Flex3 なら解説のページが見つかったのですが、Flash CS3 でクラスマッピングまでやろうとすると、結構ハマりました。なので、今日やったことをメモしときます。AS3.0 と PHP5 です。


amfphp をダウンロード

↓のページから amfphp 1.9 beta2 ( amfphp-1.9.beta.20080120.zip ) をダウンロードします。
http://sourceforge.net/project/showfiles.php?group_id=72483#files

ダウンロードしたファイルを解凍すると、中に amfphp という名前のフォルダが入っているので、それをまるごとサーバにアップします。
例えば、http://sample.innerchild.jp/amfphp/ にアップしたとします。


AS を書く。

AS 側は ( 僕のやったやり方では ) ファイルを3つ作成します。

先ずはドキュメントクラス、RemotingTest.as

package
{
import flash.display.Sprite;
import flash.net.Responder;
import flash.net.registerClassAlias;
import Params;
public class RemotingTest extends Sprite
{
private var rs:RemotingService;
function RemotingTest()
{
init();
}
private function init():void
{
// amfphp フォルダ内にある、gateway.php の URL を引数に指定。
rs = new RemotingService("http://sample.innerchild.jp/amfphp/gateway.php");
// responder を作成。Flash Remoting に成功なら onResult 、失敗なら onFault が呼ばれる。
var responder:Responder = new Responder(onResult, onFault);
// Params クラスのエイリアスを "Params" と登録する。
registerClassAlias("Params", Params);
var params:Params = new Params();
params.arg1 = "somthing";
params.arg2 = int(2);
// Test.php の メソッド test を 呼びたい時は、第1引数に "Test.test" と指定。
// 第3引数に php 側に送る、AS のオブジェクトを指定。
rs.call("Test.test", responder, params);
}
private function onResult(result:Object):void
{
trace(result); // [object Params]
}
private function onFault(fault:Object):void
{
trace(fault);
}
}
}


次に、RemotingService.as

package
{
import flash.net.NetConnection;
import flash.net.ObjectEncoding;

public class RemotingService extends NetConnection
{

function RemotingService(url:String)
{
// エンコーディング を AMF3 で。
objectEncoding = ObjectEncoding.AMF3;
connect(url);
}
}
}


AS ファイルの3つ目。データをやりとりするためのクラス ( DataTransferObject ) として Params.as 作成。

package 
{
public class Params
{
public var arg1:String;
public var arg2:int;
}
}


php も書く。

クラスマッピングをするために、php 側でも Params.php を作成しておきます。

<?php
class Params
{
// AS 側で登録したエイリアス "Params" を指定 $_explicitType に指定。
public $_explicitType = "Params";
public $arg1;
public $arg2;
}
?>


そして、Flash からデータを渡す Test.php

<?php
class Test
{
function test($params)
{
//Params オブジェクトをそのまま返す。
return $params;
//↓のように書けば、Params オブジェクトの arg1 プロパティにアクセスできます。
//return $params->arg1;
}
}
?>

作成したら、Test.php は http://sample.innerchild.jp/amfphp/services/Test.php に、Params.php は /amfphp/services/ 内に vo フォルダを作り、その vo フォルダ内にアップします。
( なぜ vo フォルダを作るかと言うと、/amfphp/globals.php の 13行目で、$voPath = "services/vo/"; と設定されているからです。)


fla ファイルをパブリッシュ

最後に、fla ファイルの ドキュメントクラスを RemotingTest に設定し、パブリッシュします。Flash 側で作成された、Params オブジェクトが php 側に渡り、また Flash に返ってきて、[object Params] と trace されれば成功です。AS → PHP、PHP → AS と双方向にクラスマッピングできたことになります。


参考

AS、php 共にこちらを参考にしました。
Oscar Trelles - Interaction Architect, Flash Developer
それと、こちらの記事も大変参考になりました。
AMFPHP1.9b2のカスタムマッピングでハマる - hirossy javaとFlex2と。



Warning: include() [function.include]: URL file-access is disabled in the server configuration in /virtual/innerchild/public_html/2008/06/26-022552.php on line 204

Warning: include(http://innerchild.jp/relavant.php?url=http://innerchild.jp/2008/06/26-022552.php) [function.include]: failed to open stream: no suitable wrapper could be found in /virtual/innerchild/public_html/2008/06/26-022552.php on line 204

Warning: include() [function.include]: Failed opening 'http://innerchild.jp/relavant.php?url=http://innerchild.jp/2008/06/26-022552.php' for inclusion (include_path='.:/usr/local/lib/php') in /virtual/innerchild/public_html/2008/06/26-022552.php on line 204


この記事を ブックマーク :   


<< Google Developer Day サポーターになると得する10のこと。 | Flash CS3 と amfphp 1.9 beta2 で Flash Remoting + クラスマッピング | 携帯を新しくしました、が。 >>

TrackBack

このエントリーのトラックバックURL:
http://innerchild.jp/mt/mt-tb.cgi/257

コメント (2)

やばいくらい参考になりました。
涙でました。

flasher の方ですかね。。
お役に立てたようで何よりです。

コメントを投稿

(いままで、ここでコメントしたことがないときは、コメントを表示する前にこのブログのオーナーの承認が必要になることがあります。承認されるまではコメントは表示されません。そのときはしばらく待ってください。)


Warning: include() [function.include]: URL file-access is disabled in the server configuration in /virtual/innerchild/public_html/2008/06/26-022552.php on line 382

Warning: include(http://innerchild.jp/right-bar.php) [function.include]: failed to open stream: no suitable wrapper could be found in /virtual/innerchild/public_html/2008/06/26-022552.php on line 382

Warning: include() [function.include]: Failed opening 'http://innerchild.jp/right-bar.php' for inclusion (include_path='.:/usr/local/lib/php') in /virtual/innerchild/public_html/2008/06/26-022552.php on line 382

Warning: include() [function.include]: URL file-access is disabled in the server configuration in /virtual/innerchild/public_html/2008/06/26-022552.php on line 389

Warning: include(http://innerchild.jp/right-bar2.php) [function.include]: failed to open stream: no suitable wrapper could be found in /virtual/innerchild/public_html/2008/06/26-022552.php on line 389

Warning: include() [function.include]: Failed opening 'http://innerchild.jp/right-bar2.php' for inclusion (include_path='.:/usr/local/lib/php') in /virtual/innerchild/public_html/2008/06/26-022552.php on line 389

Warning: include() [function.include]: URL file-access is disabled in the server configuration in /virtual/innerchild/public_html/2008/06/26-022552.php on line 456

Warning: include(http://innerchild.jp/google_analytics.php) [function.include]: failed to open stream: no suitable wrapper could be found in /virtual/innerchild/public_html/2008/06/26-022552.php on line 456

Warning: include() [function.include]: Failed opening 'http://innerchild.jp/google_analytics.php' for inclusion (include_path='.:/usr/local/lib/php') in /virtual/innerchild/public_html/2008/06/26-022552.php on line 456