Actionscript 3 将PHP4中的变量导入Flash

Actionscript 3 将PHP4中的变量导入Flash,actionscript-3,php4,Actionscript 3,Php4,在将PHP脚本实现到更大的项目中之前,我试图从PHP脚本中导入变量。到目前为止,我得到的只是头痛 // this is all thats in test.php other than the open and close brackets. // Normally I'd have it doing a mysql_query and putting useful information into the print statement. print( "lamegame.net/test/t

在将PHP脚本实现到更大的项目中之前,我试图从PHP脚本中导入变量。到目前为止,我得到的只是头痛

// this is all thats in test.php other than the open and close brackets.
// Normally I'd have it doing a mysql_query and putting useful information into the print statement.
print( "lamegame.net/test/test.php?val=foo&id=0000&name=Glenn");
test.as所要做的就是访问这三个变量。问题在于“val”未定义。然而,id和name变量很好,分别返回0000和Glenn

package {

    import flash.display.MovieClip;
    import flash.text.TextField;
    import flash.events.*;
    import flash.net.*;

    public class test extends MovieClip
    {
        public function test() 
        {
            super();
            //prep request
            //EDIT: sorry, I realize now it makes a bit of difference between test.php by itself and http://.../test.php.
            var request:URLRequest = new URLRequest("http://somewebsite.com/test.php");
            request.method = URLRequestMethod.GET;

            var loader:URLLoader = new URLLoader();

            //load request
            loader.dataFormat = URLLoaderDataFormat.VARIABLES;
            loader.addEventListener(Event.COMPLETE, dataLoaded);
            loader.load(request);
        }

        public function dataLoaded(e:Event):void
        {
            var name = e.target.data.name;
            var id = e.target.data.id;
            var val = e.target.data.val;
            trace("Val: " + val + "ID: " + id + " Name: " + name);
        }
    }
}

如何在flashide中使用php解析器对我来说很神秘。在URL请求中使用http://链接。为什么不直接使用php动态生成的xml呢。它更具可读性。或者使用swfobject和flash变量。然后只需将它们插入javascript字符串中

说我疯了,但是让php文件吐出一个xml提要供您的swf使用不是更简单吗?xml在as3中是原生的,您甚至不必解析它,只要加载它就可以了。

PHP4?你是认真的吗?它非常古老。获取PHP5。在这件事上我没有选择,这是我的教授提供给我的。啊,我明白了,很抱歉。我要把没有正确输入字符串归咎于睡眠不足。这是一个http://.../test.php 虽然我不确定这是否会有很大的不同,但我想我明白你的意思。我将尝试一下XML选项。不过我不确定我会如何尝试你的其他建议?我需要检查Javascript。您需要以某种格式返回数据。XML是一个很好的建议,ActionScript和E4X让它变得简单。另一个解决方案是JSON+1看起来我确实错过了学校里的一些东西。。。好的,我现在要讲XML。看起来我需要在test.php中对字符串进行urlencode()编码,否则在为test.as打印字符串时会丢失。我假设我需要在test.as中调用decode,否则它将被URLLoader自动调用?现在,看起来我甚至不需要进行urlencode。我现在已经开始工作了,谢谢大家的帮助!是的。最后,这就是我为了让它工作而做的。至于从AS3->PHP发送变量,我最终使用了post。因为某种原因,这样做似乎更容易。