0

我的 AS3 中有一个经常调用 PHP 文件的函数。它失败并抛出我在标题中使用的错误。我总是收到此错误消息。但是当我在浏览器中运行它时,它工作正常。我不知道似乎是什么问题。这是我的代码:

    $function checkComplete(evt:MouseEvent):void {

    // Create A new URLVariables instance to store the variable
    var myVariables:URLVariables = new URLVariables();

    // Create a variable (e.g. username) to send
    myVariables.username = candidate_txt.text;

// Create a new URLRequest instance sending data to "ascom01.php"
var myRequest:URLRequest = new URLRequest("apm01.php");

// Send data using the POST method
myRequest.method = URLRequestMethod.POST;

// The data property of the request is set to the
// URLVariables instance (myVariables) to send to the PHP file.
// Note: myVariables stored the variable (e.g. candidate)
myRequest.data = myVariables;

// Create a new instance of the URLLoader class to work with.
// URLLoader.load( ) method should be used when we need the 
// sent variables returned back to Flash ActionScript.
var myLoader:URLLoader = new URLLoader;

//specify dataFormat property of the URLLoader to be "VARIABLES"
//This ensure that the variables loaded into Flash with the same variable names
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

//Load the PHP file by using URLRequest
myLoader.load(myRequest);

//Listen when the loading of data COMPLETE
//Call the loadComplete function when the loading COMPLETE
myLoader.addEventListener(Event.COMPLETE, loadComplete);

}

// Hook up the button with the function checkComplete
enter_btn.addEventListener(MouseEvent.CLICK, checkComplete);

// This is the function that display the data returned back from PHP file
function loadComplete(evt:Event):void {

//Display the value with variable name "totalItem"
total_txt.text = evt.target.data.totalItem

//Get the value (string) with variable name "phpConfirm"
var myResult:String = evt.target.data.phpConfirm;

//Split the string into an Array
var myArray:Array = myResult.split("|");
//output_txt.text = "The number of items are: " + myArray.length;

var finalString = "";
var i:int;
for (i = 0; i < myArray.length; i++) {

finalString = finalString + myArray[i] + "<br>";
    }

    output_txt.htmlText = finalString;


    }`
4

2 回答 2

0

出现此异常是因为您必须将 php 文件部署到 php-server。Flash 无法运行 php 代码。您试图从磁盘 C 启动它。

所以

var myRequest:URLRequest = new URLRequest("apm01.php");

应该是这样的

var myRequest:URLRequest = new URLRequest("http://myhost:80/example/apm01.php");

否则,您可以将 Flash 文件上传到服务器上的同一文件夹,然后从那里启动它。

于 2012-08-21T11:13:45.713 回答
0

我的解决方案可能对这个板上的其他人来说是显而易见的......但我对此一无所知:

我从我的 Flash 文件链接到的 PHP 文件是我在我的服务器上创建的一个新文件。它具有标准的 666 权限。一旦我将权限设置为 644,一切都很顺利。

于 2013-01-30T16:22:21.067 回答