Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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
将一个数组从php发送到as3.0_Php_Arrays_Actionscript 3_Flash - Fatal编程技术网

将一个数组从php发送到as3.0

将一个数组从php发送到as3.0,php,arrays,actionscript-3,flash,Php,Arrays,Actionscript 3,Flash,我正在使用as3在flash cs6中构建一个air应用程序。我需要从php向flash as3.0发送一个数组 我想在我的应用程序上创建一个“时间表”。 我读了很多参考资料,但没有多少帮助。 这是我使用的代码。 timeline.php文件 require_once "connect.php"; $action = isset($_GET['action'])?$_GET['action']:''; $body_nama = array(); $body_postingan = array()

我正在使用as3在flash cs6中构建一个air应用程序。我需要从php向flash as3.0发送一个数组 我想在我的应用程序上创建一个“时间表”。 我读了很多参考资料,但没有多少帮助。 这是我使用的代码。 timeline.php文件

require_once "connect.php";
$action = isset($_GET['action'])?$_GET['action']:'';
$body_nama = array();
$body_postingan = array();
$total_likers = array();
$id = array();
switch($action){
    case 'posting':
    posting();
    break;
    case 'like':
    like();
    break;
    case 'delet_ini':
    deletIni();
    break;
    case 'load_timeline':
    loadTimeline();
    break;
    case 'load_timeline_lama':
    loadTimelineLama();
    break;
}
function loadTimeline(){
    global $body_nama;
    global $body_postingan;
    global $total_likers;
    global $id;

    $query_total = "SELECT COUNT(*) FROM timeline_posts";
    $result_total = mysql_query($query_total);
    $total = mysql_result($result_total,0);

    for ($i =0; $i<=9; $i++){
        $query_timline = "SELECT * FROM timeline_posts WHERE id = ('$total'-'$i')";
        $result = mysql_query($query_timline);
        while ($data = mysql_fetch_array($result)){
            $body_nama[$i] = htmlentities($data['timeline_name']);
            $body_postingan[$i] = htmlentities($data['timeline_post']);
            $id[$i] = htmlentities($data['id']);
            print "nama[$i]=$body_nama[$i]";
            print "postingan[$i]=$body_postingan[$i]";
            print "id[$i]=$id[$i]";
        }
    }
}
但我有错误

TypeError:Error#1010:术语未定义且没有属性。在 Function/MasagiApp\u fla:main timeline/loadTimeline/MasagiApp\u fla:onCompleteLoadTimeline()[MasagiApp\u fla.main timeline::frame6:52] at flash.events::EventDispatcher/dispatchEventFunction()at flash.events::EventDispatcher/dispatchEvent()位于 flash.net::urloader/onComplete()


请帮助我

不要在操作时将数据组合成字符串。在您的例子中,结果不是有效的url编码字符串(例如缺少&),并且它也不会像您在代码中期望的那样自动转换为数组

JSON或XML是一种更好的数据交换格式,特别是当它具有某种结构时。我用前者来回答这个问题

说到结构,将属于多个阵列的数据分布在一起是一种糟糕的结构。不要有许多具有单个属性的数组,而是一个数组,其中包含将属性分组在一起的对象

在您的例子中,一个对象具有属性
name
posting
ID
,这些属性在JSON中类似:

{
    "name":"foo",
    "posting":"bar",
    "ID":"123"
}
由于有许多这样的对象,它们位于一个数组中:

[
    {
        "name":"foo",
        "posting":"bar",
        "ID":"123"
    },
    {
        "name":"foo000oo",
        "posting":"baAAaar",
        "ID":"456"
    }
]
这就是来自服务器的响应主体的外观。 在PHP中,您可以使用
mysqli\u fetch\u assoc()
json\u encode()
将数据库中的数据转换为json表示形式

在客户端(是的,@是正确的,您不应该将函数相互嵌套!)将收到的字符串转换为通用As3
对象,结果是:

function onCompleteLoadTimeline(event:Event)
{
    var result:Object = JSON.parse(event.target.data);

    trace (result[0].name);  // should give first name
}

我认为您应该将
onCompleteLoadTimeline
函数移到
loadTimeline
函数之外。这要归功于响应速度非常快,但输出没有变化。
function onCompleteLoadTimeline(event:Event)
{
    var result:Object = JSON.parse(event.target.data);

    trace (result[0].name);  // should give first name
}