对不起,令人困惑的标题,并不完全知道如何说话。我一直在关注一个交互式动态Flash ActionScript 3.0游戏的教程,该游戏与php和MySQL进行通信以记住每个用户的某些信息。它首先向PHP文件getsessionvars.php发送一个请求,该请求返回闪存游戏可以用来取消用户信息的值。基本上这里是所有重要的代码,从动作开始:在舞台上有多个玩家动作3.0 php MySQL
stop();
// Assign a variable name for our URLVariables object
var variables:URLVariables = new URLVariables();
// Build the varSend variable
// Be sure you place the proper location reference to your PHP config file here
var varSend:URLRequest = new URLRequest("getsessionvars.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
// Build the varLoader variable
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
variables.myRequest = "bringit";
// Send the data to the php file
varLoader.load(varSend);
// When the data comes back from PHP we access it here
function completeHandler(event:Event):void{
var idVar = event.target.data.id_var;
var userNameVar = event.target.data.uname_var;
var passVar = event.target.data.upass_var;
var resultStatus = event.target.data.my_result;
var coordX=event.target.data.coordx;
var coordY=event.target.data.coordy;
if (resultStatus == "no_session"){
gotoAndStop("no_session");
} else if (resultStatus == "no_exist"){
gotoAndStop("no_exist");
} else if (resultStatus == "all_good"){
userid_txt.text = idVar;
username_txt.text = userNameVar;
password_txt.text = passVar;
gotoAndStop(5);
var other:otherPeople = new otherPeople();
addChild(other);
other.x=coordX;
other.y=coordY;
}
}
然后getsessionvars.php:
<?php
session_start();
include_once("php_includes/check_login_status.php");
$id = ""; // Initialize $id var
$username = ""; // Initialize $username var
$password = ""; // Initialize $password var
if (isset($_POST['myRequest']) && $_POST['myRequest'] == "bringit"){
$id = preg_replace('#[^0-9]#i', '', $log_id);
$username = preg_replace('#[^a-z0-9]#i', '', $log_username);
$password = preg_replace('#[^a-z0-9]#i', '', $log_password);
// Check database to see if the id is related to this password
include_once("connect.php");
mysql_query("INSERT INTO online ('id','player','xpos','ypos') VALUES('','{$username}','10','30')");
$sql = mysql_query("SELECT * FROM users WHERE id='$id' AND username='$username' LIMIT 1");
$numrows = mysql_num_rows($sql);
$sqla=mysql_query("SELECT * FROM online");
echo "my_result=all_good&id_var=$id&uname_var=$username&upass_var=$password&coordx=30&coordy=50";
}// close inital if condition
?>
我的问题是:我怎样才能让这个多个用户可以出现在屏幕在同一时间?正如你可以注意到的,我已经试图存储玩家首次登录MySQL数据库时的坐标,然后希望每次角色移动时都更新这些信息,但我想知道是否还有更多这样做的有效方法?