0

我正在涉足 Flash 开发,想知道如何将一些变量发布到 URL。假设用户玩了一个 Flash 游戏,该游戏被打包为嵌入在 HTML 中的 EXE 或 SWF,存储在用户的计算机上,而不是来自某个网​​页,并且想通过填写一个简单的表格来注册分数,只需要一个电子邮件地址和按下按钮。

即使 Flash 应用程序不在活动网页上,是否也可以这样做?

4

2 回答 2

3

如果在网页上或在本地计算机上,则方法相同。您可以执行以下操作:

(未经测试的代码)

var request:URLRequest = new URLRequest("http://yoursite.com/yourpage.php");
request.method = URLRequestMethod.POST;     
request.data = "emal=someemail@email.com&score=79597";

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, callWasMade);
loader.addEventListener(IOErrorEvent.IO_ERROR, callFailedIOError);
loader.load(request);

function callWasMade(evt:Event):void{
  //Optionally check server response
}
function callFailedIOError(evt:IOErrorEvent):void {
   //Holy crap I can't reach my server!
}
于 2011-12-07T19:22:13.513 回答
2

这是可能的,但您需要一些服务器端脚本以及 PHP 等。查看http://www.gotoandlearn.com以获得一些很棒的教程。

基本上,您创建一个 URLRequest 到服务器端脚本并用它发送一些数据。您可以使用 URLVariables 将数据传递给脚本。然后脚本可以接收数据并将其保存在数据库中或发送邮件。

这来自 Adob​​e 文档: http ://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLVariables.html

public function URLVariablesExample() {
            var url:String = "http://www.example.com/script.php";
            var request:URLRequest = new URLRequest(url);
            var variables:URLVariables = new URLVariables();
            variables.exampleSessionId = new Date().getTime();
            variables.exampleUserLabel = "guest";
            request.data = variables;
            navigateToURL(request);
        }

在 PHP 方面,您可以执行以下操作:

$exampleSessionId = $_REQUEST['exampleSessionId'];
$exampleUserLabel = $_REQUEST['exampleUserLabel'];
$message = "Id: " . $exampleSessionId . ", Label: " . $exampleUserLabel;
mail('toaddress@example.com', 'My Subject', $message);
于 2011-12-07T19:17:33.177 回答