Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3-从PHP echo读取字符串_Php_Actionscript 3_String_Variables - Fatal编程技术网

Actionscript 3-从PHP echo读取字符串

Actionscript 3-从PHP echo读取字符串,php,actionscript-3,string,variables,Php,Actionscript 3,String,Variables,我有一个用echo打印的php脚本: “&string=“汤姆、迪克、哈利”” 我需要把“汤姆,迪克,哈利”放在一个动作脚本字符串中,我必须把它分成一个数组。我在读取php输出时遇到问题,我以这种方式使用URLLoader和URLvariables类 var myRequest:URLRequest = new URLRequest("ip/directory/script.php"); var myLoader:URLLoader = new URLLoader

我有一个用echo打印的php脚本: “&string=“汤姆、迪克、哈利””

我需要把“汤姆,迪克,哈利”放在一个动作脚本字符串中,我必须把它分成一个数组。我在读取php输出时遇到问题,我以这种方式使用URLLoader和URLvariables类

        var myRequest:URLRequest = new URLRequest("ip/directory/script.php");
        var myLoader:URLLoader = new URLLoader();           

        function onLoaded(event:Event):void {
            var variables:URLVariables = new URLVariables( event.target.data );
            modelli = variables.string.split(",");
            caricaColori(modelli[0]);
        }

        myLoader.addEventListener(Event.COMPLETE, onLoaded);
        myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
        myLoader.load(myRequest);

我做错了什么

也许使用非保留的变量名会有所帮助<代码>字符串似乎是一个糟糕的选择。

虽然您在使用URLVariables时遇到了问题,但我仍然不能完全理解这一点

function onLoaded(event:Event):void {
        var variables:URLVariables = new URLVariables( event.target.data );
        modelli = variables.string.split(",");
        caricaColori(modelli[0]);
    }
为什么需要将其存储到URLVariables实例中?为什么不直接解析它呢。若您害怕“&string=”,则不需要在PHP端回显它,也可以在Actionscript端将其切掉

modelli = event.target.data.split(",");
如果您想添加更多变量,我建议将php响应转换为xml文件。URL变量应用于向服务器发送数据,而不是解析服务器响应。

您的问题是,您正在将变量加载到URLVariables容器中,然后尝试对其调用字符串函数。我会这样做:

function onLoaded(event:Event):void {
    //load data as a string
    var variables:String = event.target.data;

    //make a new array
    var modelli:Array = new Array();
    modelli = variables.split(",");

    //possibly pop the array
    modelli.pop(); //pop off the last empty element of array

    caricaColori(modelli[0]);
 }

加载此PHP数据时,很有可能需要从数组中弹出()最后一个元素,因为它将是一个空字符串。

您有什么问题?我觉得你忘记提到实际问题了。关键字区分大小写。字符串是关键字,而不是字符串。很糟糕的选择是的,但不应该破坏任何东西。非常感谢你的回答,我按照你的建议解决了更改回声格式的问题
   function onLoaded(event:Event):void {
        var variables:URLVariables = new URLVariables( event.target.data );
        modelli = variables.string.split(",");
        caricaColori(modelli[0]);
    }
function onLoaded(event:Event):void {
    //load data as a string
    var variables:String = event.target.data;

    //make a new array
    var modelli:Array = new Array();
    modelli = variables.split(",");

    //possibly pop the array
    modelli.pop(); //pop off the last empty element of array

    caricaColori(modelli[0]);
 }