gpt4 book ai didi

php - 如何将变量从 PHP 传递到 Flash (ActionScript 3)

转载 作者:行者123 更新时间:2023-11-29 06:28:23 25 4
gpt4 key购买 nike

我需要从 MySql 数据库中选择游戏编号并将其传递给 Flash 游戏 (ActionScript 3)。

现在我有 AS3 代码:

function getVars(e:Event):void{
var req:URLRequest = new URLRequest("top.php");
var loader:URLLoader = new URLLoader(req);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, getVarComplete);
}

function getVarComplete(e:Event):void{
var gameNr.text = e.target.data;
}

这是 PHP 代码(我不知道选中的行如何传递给变量并将其发送到 flash)

$id = $_SESSION['id']; 
$mysqli = new mysqli("localhost","xxx","xxx","xxx");

$query = "SELECT GameNr
FROM Game
WHERE FBId = '". mysql_real_escape_string($id) ."'
ORDER BY PlayTime DESC LIMIT 1";

更新:

如果我使用以下 PHP:

<?php 
session_start();
$id = $_SESSION['id'];

$mysqli = new mysqli("localhost","xx","xx","xx");

$query = "SELECT GameNr
FROM Game
WHERE FBId = '". mysql_real_escape_string($id) ."'
ORDER BY PlayTime DESC LIMIT 1";
if (!$mysqli->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
}

if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
echo $row["GameNr"];
}
$result->free();
}
$mysqli->close();
?>

www.myhost.com/top.php 返回正确值 NA==


如果我使用以下 AS3 代码:

function onVarsLoaded(e:Event) {
var msg:String = "Communication with the server was successful.\n\n";
msg += "foo -> "+e.target.vars.foo+"\n";
trace(msg);
}

它返回给我:foo -> undefined

如果我改变这个

msg += "foo -> "+e.target.vars.foo+"\n";

msg += "foo -> "+e.target.vars+"\n";

它返回错误的值:foo -> NA=%3D

最佳答案

试试这个:

AS3:

import net.kaegi.loaders.VarLoader;
var vl:VarLoader;

sendBtn.addEventListener(MouseEvent.CLICK,sendBtnHandler);
function sendBtnHandler(e:MouseEvent) {
// Variables sent by POST-Method:
var varObj:Object = {};
varObj.textinput0 = escape(textinput0.text);
varObj.textinput1 = escape(textinput1.text);

vl = new VarLoader("http://yourserver.com/landing.php?foo=foo", varObj);
vl.addEventListener(Event.COMPLETE, onVarsLoaded);
vl.addEventListener(Event.CANCEL, onVarsCancel);
}

function onVarsLoaded(e:Event) {
var msg:String = "Communication with the server was successful.\n\n";
msg += "foo -> "+e.target.vars.foo+"\n";
tf_servermsg.textColor = 0x009900;
tf_servermsg.text = msg;
}

function onVarsCancel(e:Event) {
tf_servermsg.textColor = 0x990000;
tf_servermsg.text = e.target.errormsg;
}

PHP

// handle coming get
$foo = $_GET["foo"];

// handle coming post from flash
$textinput0 = $_POST["textinput0"];
$textinput1 = $_POST["textinput1"];

// send it to flash
$yourdata = "hello world"; // your mysql data here


echo $yourdata;

关于php - 如何将变量从 PHP 传递到 Flash (ActionScript 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29470572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com