jeudi 26 janvier 2017

ActionScripts 3 read JSON from PHP issue

I'm trying to read JSON data from localhost PHP in ActionsScripts3, I found some code to do it but this code doesn't works.

PHP:

<?php 
$arr = array ('DATA1'=>"111",'DATA2'=>"222");
header('Content-Type: application/json');
echo json_encode($arr);
?>

AS3:

import flash.display.*;
import flash.events.*;
import flash.net.*;


var urlLoader:URLLoader=new URLLoader();

function ReadJsonPhp () :void
        {
            addEventListener(Event.ADDED_TO_STAGE,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 have 3 function if possible i like to use only 1 function.

Aucun commentaire:

Enregistrer un commentaire