簡単!! 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> |