0

I am building an air app in flash cs6 using as3. My database is on a web server and I use php to connect to my app, I need to send an array from php to as3 and populate it in a list in my app, I just need to know how to send and receive an array so I can print it in my app thanks

2
  • 1
    Send an array from PHP to as3? Do you mean have as3 contact the PHP server? For starters have you looked at URLRequest and JSON.parse? Commented Jun 10, 2013 at 3:46
  • possible duplicate of How can I pass an array from PHP to Actionscript 3/Flash? Commented Jun 10, 2013 at 6:41

2 Answers 2

2

Try this:

Actionscript 3

import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;

var urlLoader:URLLoader=new URLLoader();
urlLoader.load(new URLRequest("http://example.com/json.php"));
urlLoader.addEventListener(Event.COMPLETE, urlLoaderCompleteHandler);

function urlLoaderCompleteHandler(e:Event):void {
    var json:Object=JSON.parse(urlLoader.data);
}

Now within urlLoaderCompleteHandler you can handle json as an object.

PHP

<?php
    $data=array("test"=>"Hello World!");
    header('Content-type: application/json');
    echo json_encode($data);
?>
Sign up to request clarification or add additional context in comments.

2 Comments

Not quite sure why you deleted this - to me it looks better than the other answer here.
@Flexo Tidying up some old answers, it didn't look like it was going to help anyone so I deleted it.
1

Use JSON

on the AS3 side you can find docs here

on the php side use json_encode and json_decode

1 Comment

Note that JSON is only available if you're targeting Flash Player 11+. For earlier versions, you can download a library here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.