簡単!! Ming(PHP)のActionScript サーバーと通信

戻る
 フラッシュはサーバーとメッセージのやり取りを行う事ができます。 この機能をうまく使えうことで、チャットゲームを造ったり、 オンラインゲームのセーブデータをユーザーに保管してもらったり、ゲームのランキングを作ったり、 ホームページの管理ソフトを作成したりと行った事がてきるようになります。

使い方は サーバーとの連携 での解説を読んでいただくとして、今回はデータの送受信の機能をObject化することにします。

(サーバー側のプログラムにはPHPを用います。サーバーはapacheをしようしています。)

Action.php Exe.php Movie.php Object.php Sender.php


#Movie.phpのActionScriptの部分
	return new SWFAction
	("
	_root.onEnterFrame = function()
	{
	    if(_root._x != -1 )
		{
		    _root.init(_root);
		    _root._x =-1;
		}
	};
	_root.init = function(mc)
	  {
		 for(m in mc)
			{
			if(typeof(mc[m])=='movieclip')
			{
			mc[m].init();
			_root.init(mc[m]);
			}
			}
		 gam  = this.sender.new();
		 gam.send(gam); 
	   };
	");



#Sender.phpのActionScriptの部分
	 public function getAction()
         {
            return new SWFAction
 		("
		var number;
		init =function()
		{
		number = -1;
		};
		new  = function()
		{
		number++;
		createEmptyMovieClip('cgi'+number,number);
		this['cgi'+number].name ='hellocgi';
		this['cgi'+number].send =this.send;
		return this['cgi'+number];
		};
		send = function()
		{
		lo = new LoadVars();
		lo.name = this.name;
		lo.contentType('application/x-www-form-urlencoded');
		lo.send('http://127.0.0.1/~actionscript/Action.php','_blank','POST');
		};
		");
         }


#Action.php データを受け取る部分
<html>
<head>
<title>Test from Action script </title>
</head>
<body>
<?php
print "sdfsdf";
print $_POST["name"] . "<br>";
?>

</body>
</html>

PC用眼鏡【管理人も使ってますがマジで疲れません】 解約手数料0円【あしたでんき】 Yahoo 楽天 NTT-X Store

無料ホームページ 無料のクレジットカード 海外格安航空券 ふるさと納税 海外旅行保険が無料! 海外ホテル