【问题标题】:Unknown error communicating between PHP and ActionscriptPHP 和 Actionscript 之间的未知错误通信
【发布时间】:2013-10-10 16:24:01
【问题描述】:

我遇到了一个非常简单或非常复杂的问题,由您自己来解决。我一直在努力尝试将 URL Loader 类合并到初学者图形程序 - Stencyl 中。我精通 HTML、CSS 和 PHP,但 actionscript 对我来说是全新的,所以我真的可以用手使用。这是我所拥有的: 我的域上托管了 4 个文件:

网页.html

样式表.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.";

}

?>

由于某种原因,这不起作用。结果只是两个空白文本字段,并且是一个动作脚本菜鸟,我不知道发生了什么。任何帮助将不胜感激。感谢您的宝贵时间。

【问题讨论】:

    标签: php actionscript-3 flash communication urlloader


    【解决方案1】:

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

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

    例如DisplayObject.filtersContextMenu.customItemsURLRequest.data 的情况。

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

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

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

    【讨论】:

    • 其实这段代码还是有问题的。似乎没有回应。会不会是 Flash 安全问题?
    猜你喜欢
    • 1970-01-01
    • 2016-09-23
    • 2011-08-23
    • 2012-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多