I am trying to read JSON data from localhost PHP in ActionsScripts3, I found code for this, but this code does not work.
PHP:
<?php
$arr = array ('DATA1'=>"111",'DATA2'=>"222");
header('Content-Type: application/json');
echo json_encode($arr);
?>
AS3:
import flash.events.*;
import flash.net.*;
var urlLoader:URLLoader=new URLLoader();
function ReadJsonPhp () :void
{
addEventListener(Event.COMPLETE,init);
}
function init(event:Event)
{
urlLoader.load(new URLRequest("http://localhost/asphp.php"));
urlLoader.addEventListener(Event.COMPLETE, urlLoaderCompleteHandler);
}
function urlLoaderCompleteHandler(e:Event):void
{
trace(e.target.data) ;
var arrayReceived:Object = JSON.parse(e.target.data);
}
ReadJsonPhp();
This code has 3 functions, if possible, I like to use only 1 function.
source
share