PHP和Actionscript之间的通信出现未知错误

PHP和Actionscript之间的通信出现未知错误,php,actionscript-3,flash,communication,urlloader,Php,Actionscript 3,Flash,Communication,Urlloader,我有一个问题,要么简单得离谱,要么复杂得离谱,这取决于你去发现。我一直在努力将URL加载器类合并到初学者图形程序-Stencyl中。我精通HTML、CSS和PHP,但actionscript对我来说是全新的,所以我真的可以用一只手。以下是我得到的: 我的域上托管有4个文件: Webpage.html Stylesheet.css RequestData.php FlashDoc.swf html和css代码很简单,没有问题,swf文件嵌入到html文档中。flash文件是一个简单的表单,包含一个

我有一个问题,要么简单得离谱,要么复杂得离谱,这取决于你去发现。我一直在努力将URL加载器类合并到初学者图形程序-Stencyl中。我精通HTML、CSS和PHP,但actionscript对我来说是全新的,所以我真的可以用一只手。以下是我得到的: 我的域上托管有4个文件:

Webpage.html

Stylesheet.css

RequestData.php

FlashDoc.swf

html和css代码很简单,没有问题,swf文件嵌入到html文档中。flash文件是一个简单的表单,包含一个文本字段、提交按钮和两个动态文本字段。守则如下:

// Btn listener
submit_btn.addEventListener(MouseEvent.CLICK, btnDown);
// Btn Down function
function btnDown(event:MouseEvent):void {


// 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("http://www.mywebsite.com/config_flash.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.uname = uname_txt.text;
variables.sendRequest = "parse"; 
// Send the data to the php file
varLoader.load(varSend);

// When the data comes back from PHP we display it here 
function completeHandler(event:Event):void{

var phpVar1 = event.target.data.var1;
var phpVar2 = event.target.data.var2;

result1_txt.text = phpVar1;
result2_txt.text = phpVar2;

} 


}
然后我有一个包含以下代码的小PHP文件:

<?php
// Only run this script if the sendRequest is from our flash application
if ($_POST['sendRequest'] == "parse") {
// Access the value of the dynamic text field variable sent from flash
$uname = $_POST['uname'];
// Print  two vars back to flash, you can also use "echo" in place of print
print "var1=My name is $uname...";
print "&var2=...$uname is my name.";

}

?>


出于某种原因,这是行不通的。结果只有两个空白文本字段,作为一个ActionScriptNoob,我不知道发生了什么。任何帮助都将不胜感激。谢谢您的时间。

如果您不习惯AS3,您的问题的答案既简单又令人惊讶

在AS3中,当使用setter时,flash.*类倾向于生成并存储传递对象的副本。 由于它们存储副本,因此setter之后对原始实例的任何修改都不会应用于副本,因此将被忽略

例如,
DisplayObject.filters
ContextMenu.customItems
URLRequest.data

在代码中,在填充变量之前设置
varSend.data=variables
。你应该做相反的事情:

variables.uname = uname_txt.text;
variables.sendRequest = "parse"; 
varSend.data = variables;
// Send the data to the php file
varLoader.load(varSend);

只有一些类可以这样做,即使这样,它们通常也不会对所有的setter都这样做。

实际上,这段代码仍然存在一个问题。似乎没有回应。可能是闪存安全问题吗?