jeudi 23 juin 2016

Pass string from php to flash

I'm just trying out PHP and AS3 in Flash CS6. I want a few strings to be passed from PHP to Actionscript3 and store them in an array. Is this possible?

Currently I'm doing this. My PHP code is

    echo "one,two,three,four";

and AS3 code is:

var myRequest:URLRequest = new URLRequest("please7.php");
var myLoader:URLLoader = new URLLoader();           
myLoader.dataFormat = URLLoaderDataFormat.TEXT;
myLoader.addEventListener(Event.COMPLETE, onLoaded);

function onLoaded(event:Event):void {
    var variables:String =;
    var arr1:Array = new Array();
    arr1 = variables.split(","); 

This gives me this output:

    echo "one,two,three,four";

If I use myLoader.dataFormat = URLLoaderDataFormat.VARIABLES; instead of myLoader.dataFormat = URLLoaderDataFormat.TEXT; ..I'm getting this error

Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.

I want the output to be a simple [one two three four]

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire