简体   繁体   English

将关联数组从PHP传递到AS3问题

[英]Passing associated array from PHP to AS3 issue

I'm having a problem with passing my JSON (Converted to Array) data from PHP to ActionScript 3.0 . 将我的JSON(转换为数组)数据从PHP传递到ActionScript 3.0时遇到问题。

Here is my php code: 这是我的PHP代码:

class myTwitterOAuth {

    public function get_user($username) {

        $oauth = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret);
        $param = array('screen_name'=>'twitter');
        $data = $oauth->get('users/show', $param);
        $json = json_encode($data);
        $JSONarray=json_decode($json, true);
        return $JSONarray; //To pass the whole Array not working
    }
}

Now for my Action Script Method: 现在为我的动作脚本方法:

function whenSuccess(res:Object):void{  
    trace(res['name']); //Not working at all Neither name nor screen_name or any
}

Error I'm getting from Adobe Flash: 我从Adobe Flash获取错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at AS3PHPTesting01_fla::MainTimeline/whenSuccess()

UPDATE UPDATE

I'm using Amfphp library to communicate between PHP and Action Script. 我正在使用Amfphp库在PHP和Action Script之间进行通信。 Here is how I'm doing it: 这是我的做法:

var gateway:String = "http://website/here/Amfphp/index.php";
var connection:NetConnection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, errorConnection);
var res:Responder = new Responder(whenSuccess, whenFail);

connection.connect(gateway);
connection.call('myTwitterOAuth/get_user', res, param);

Tip: Try first to receive your results from the AMFPHP browser. 提示:首先尝试从AMFPHP浏览器接收结果。 When you receive your data correctly from the webservice in the browser you'll be able to use it in AS3.0. 当您从浏览器中的Web服务正确接收数据时,就可以在AS3.0中使用它。

Try this inside the function whenSuccess to check what you are really receiving 成功检查您真正收到的内容时,在函数内尝试此操作

for (var prop in res){
    trace(prop, res[prop]);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM