Communication between Action Script 3.0 And Server

Some days ago I developed a personal facebook application. In that application, I’ve to communicate between my flash (AS 3.0) game and my server. Now I’ve given the scenario I’ve faced:

Case 1: My target was to develop a dictionary and some simple word puzzle type games. And the application is for facebook.

Case 2: I developed and implemented the dictionary using FBJS (Facebook javascript). For data exchange format between FBJS and PHP I use JSON format (Really a lightweight format). Finally I implemented the dictionary perfectly.

Case 3: Now I chose to develop the games using FBJS. But the problem was, by seeing view source anyone could see the data come from PHP.  So, I decided to use Action Script 2.0 to develop the games. I know AS 2.0 very well but I found there are lot of changes (Core changes) in AS 3.0. So I decided to develop games using Flash Action Script 3.0. As I also want to learn the new trends of AS 3.0.

Case 4. Now I described the problem I faced to develop AS 3.0 games and to integrate them into facebook and how I solved them.

After succesfully developed the game, when data sent to flash from my server, there are 2 ways to do that from AS 3.0

First way:

var URL_TO_GO = '' + '&cache=' +new Date().getTime();
xml = new XML();
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest(URL_TO_GO));
function(evt:Event):void {
xml = XML(;

Second way:

var url:String = "";
var variables:URLVariables = new URLVariables();
variables.sessionId = new Date().getTime();
variables.userLabel = "Your Name";

var request:URLRequest = new URLRequest(url); = variables;
trace(“sendToURL: ” + request.url + “?” +;
try {
catch (e:Error) {
// handle error here

If you use first way: you’ll get the response. But if you will use second way, you will sends a URL request to a server, but ignores any response.

So, when I saved the score after finishing the game, I choose the second way. But, unfortunately in server load, I found that the second way is not working perfectly. Sometimes the requests send from flash to server is lost on the way.

So, I implemented the first way and I solved it. In server load the first way may take some times but the request it sends from flash to server didn’t lose on the way.


3 Responses to “Communication between Action Script 3.0 And Server”

  1. Kayes Says:

    You could also use flash remoting services with AMFPHP. It’s useful if the data being transferred consist of complex objects.

  2. dora games online Says:

    Very well written post. It will be supportive to anybody who utilizes it, as well as myself. Keep up the good work – looking forward to more posts.

  3. seouzmanigoogle Says:

    Thanks for your post
    Hey do you want to learn seo tools search engine optimization tools just visit my website and join seo community

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: