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";</span></code>

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 or you can get one of those best dedicated servers to enhance the loading speed

mahmud ahsan

Computer programmer and hobbyist photographer from Bangladesh, lives in Malaysia. My [Github | Business | Twitter | Linkedin | Instagram | 500px]

You may also like


  • Kayes
    October 24, 2008 at 7:20 pm

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

  • Craig
    December 15, 2009 at 10:49 pm

    First of all, I would like to say thank you for sharing your wonderful technical articles. I am happy that I found your blog site because I am now working on development of Facebook Application and searching and gathering on how to use the various parts of the Facebook Platform is really a headache.
    I’ve been searching for 2 days on how to embed a flash .swf into my Facebook Application canvas but still have no luck to get it work. Would you please give us some advices or tutorial on how to do it? Thank you very much.

  • Craig
    December 15, 2009 at 10:59 pm

    I forgot to mention why I want to embed the swf into the Facebook canvas through iframe.
    I can embed it using FBML tag fb:swf but seems it only support certain update versions of Flash player.
    But iframe seems to be more general regarding Flash player versions.
    I am also wondering which one is a better choice between iframe and FBML??

  • mahmud ahsan
    mahmud ahsan
    December 16, 2009 at 2:19 pm

    @Craig, yeah you can use fb:swf but there might be some problem when you will want to access external script. There is another problem you might be face, cross site scripting problem. Please check this link and learn about flash/facebook application development. This is really a great series.


  • Josh
    January 16, 2010 at 12:07 am

    You cannot ‘talk’ directly to your .swf. You need to use the LocalConnection object in AS3. Make sure to add the fb bridge before you fb:swf and when you retrieve your parameters there is 1 parameter for in-coming messages and 1 for outgoing.

    outgoing_connection = LoaderInfo(this.root.loaderInfo).parameters.fb_local_connection;

    ingoing_connection = LoaderInfo(this.root.loaderInfo).parameters.fb_fbjs_connection;

    Watch for fb_local_connection (IN) and
    fb_fbjs_connection (OUT)

    Facebook’s bridge is a two-way communication object.

    Hope this helps.

    Josh Molina

  • Shemeka Beckmeyer
    August 1, 2011 at 4:01 pm

    You can make money with this blog but what about a system that lets you make money without even having a website? There is a piece of software that takes the pain out of making money online. With this software, you can forget about writing articles, creating blogs, submitting to directories, building more and more websites and everything else. Obviously, this is a tactic that has never been seen before. This software system generates results in as little as 30 seconds, so there’s no waiting around for traffic or to “see if this works”. You’ll want to get in on this as soon as you can so go ahead and check out the info and watch the video ->

Comments are closed here.

About Me

Computer programmer and hobbyist photographer from Bangladesh, lives in Malaysia. My [Github | Business | Twitter | Linkedin | Instagram | 500px]


Working life at home Muaz < 4 Months Muaz and Jayed First Smile Little Angel Trees Horse Ride Maritime Museum in Malacca Dome of Blue Mosque Malaysia

Twitter Feed