-2

请帮助我,我无法在我的 .as 类中检查 php 数据这是我的 as3 代码

 if(event.target.data.msg=="all_good"){//here is the problem ,i can't understand maybe //that's why i'm using package??
        lbl.text = "all is good"; // or do something
    }

PHP代码:

 <?php
    print "msg=all_good";
 ?>

更新 :

varLoader.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(event:Event):void
{ 
  if (event.target.data.msg== "no_good"){
  staticalVars.errMsg.text = "You entered invalid password!";
  } else if (event.target.data.msg == "all_good") { 
  staticalVars.errMsg.text = "You entered correct password!"; } 
}

嗨 gyus 这里是我的整个代码。主要问题是我正确获取了我的 php 数据,我在我的 flash 代码中看到了它,但是我不能使用这些数据来做一些事情

package {
 import flash.display.Sprite;
import flash.events.*
import flash.net.*;
import fl.controls.Label;
public class test  extends Sprite{

public function test() {sendData("scripts/login.php");}
public function sendData(url:String):void {
var request:URLRequest = new URLRequest(url);
var _vars:URLVariables = new URLVariables();
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
request.data = _vars;
_vars.fio_t = "ds";
request.method = URLRequestMethod.POST;
loader.addEventListener(Event.COMPLETE, handleComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
loader.load(request);
}
private function handleComplete(event:Event):void {
var lbl:Label = new Label();
var lbl2:Label = new Label();
lbl2.text = "" + loader.data.msg; /////here, it shows me my php message 
lbl2.x = 80;
if(event.target.data.msg=="all_good"){ ///// but here doesn't, and why ??
    lbl.text = "all is good"; 
}
addChild(lbl);   
addChild(lbl2);
}
private function onIOError(event:IOErrorEvent):void {
trace("Error loading URL.");
}
}
}

myphp代码是

<?php
    echo "msg=all_good";
?>
4

1 回答 1

0

它应该是这样的:

var varloader:URLLoader = new URLLoader();
varloader.load(new URLRequest("yourfile.php"));
// This line is important to get the variables
varloader.dataFormat = URLLoaderDataFormat.VARIABLES; 
varloader.addEventListener(Event.COMPLETE, function(event:Event):void {
   trace(event.target.data.msg);
});

PHP应该是:

<?php
    print "msg=all_good";
?>
于 2013-08-26T10:39:46.300 回答