mercredi 1 mars 2017

Actionscripts3 read JSON from VPS issue

I wrote some code to read JSON data from our VPS, I think my AS3 codes are true but I'm not sure about the PHP codes. Adobe Animate console is empty after I run project.

AS3:

import flash.events.*;
import flash.net.*;
var loader: URLLoader;
var request: URLRequest;
function load(): void {
    request = new URLRequest("212.73.150.148/asphp.php");
    loader = new URLLoader();
    loader.addEventListener(Event.COMPLETE, onComplete);
    loader.addEventListener(IOErrorEvent.IO_ERROR, onError);
    loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
    loader.load(request);
}
function onError(e: Event): void {
    // handle error     
}
function onComplete(e: Event) {
    trace(e.target.data);        
    var json: Object = JSON.parse(e.target.data);
    trace("json.DATA1 = ", json.DATA1);
    trace("json.DATA2 = ", json.DATA2);
}
load();

PHP:

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

Aucun commentaire:

Enregistrer un commentaire