我在将我的 JSON(转换为数组)数据从 PHP 传递到 ActionScript 3.0 时遇到问题。
这是我的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
}
}
现在我的动作脚本方法:
function whenSuccess(res:Object):void{
trace(res['name']); //Not working at all Neither name nor screen_name or any
}
我从 Adobe Flash 得到的错误:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AS3PHPTesting01_fla::MainTimeline/whenSuccess()
更新
我正在使用 Amfphp 库在 PHP 和 Action Script 之间进行通信。这是我的做法:
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);