Flash Javascript communication first look


I did a fast research about how to make flash interact with the container website, and i collected some good information.


There are 2 main techniques to implement communications between flash and the container website:

Example: http://www.kongregate.com/developer_center/docs/kongregate-api

1- Client API technique:

Reference: http://www.adobe.com/devnet/flash/javascript_api.html

Using this technique, the flash will communicate with the website through JavaScript.

So in brief, the flash can send and receive variable from the website using Javascript, and for this first research I got 2 main ways to make flash interact with Javascript:

a- Using the ExternalInterface which exist in the action script classes, http://livedocs.adobe.com/flex/3/langref/flash/external/ExternalInterface.html, http://kb2.adobe.com/cps/156/tn_15683.html#about,

Example: http://jodieorourke.com/view.php?id=122&blog=news

b- Using normal Javascript calls as in this example: http://www.permadi.com/tutorial/flashjscommand/ which describes the main functions to interact with the flash using Javascript.

2- Server API technique:

Example: http://www.puarcade.com/demo/classic-games/snake

Using this technique, flash will call the server side APIs directly, and will post variables to the API URL, also there is another way is to send these variables using Querystrings, which will not be the right way all the time and may be not possible in some cases ‘put in mind for example the max number of query string characters’.


Most of game websites use the server side APIs, but big famous website give both options, server or client side APIs. http://www.kongregate.com/developer_center/docs/kongregate-api

Server Side advantages from my point of view:

– More secure calls.

– Works whatever the user enabled javascript in the browser or not.

– No problems with different browsers compatibilities.

Client Side advantages:

– Middle layer, between the server side code and the flash, which encapsulates the server side methods and don’t let the flash call the server APIs directly but will be through this JS layer.

– Gives the ability to submit values to the server using Ajax style ‘without refreshing the whole page’.

– The flash will need less information from the website, as the Javascript code will handle most of the common variables ‘such as the current user, the current page URL, …’.

By the way in both cases we will need to implement the server side API first and then will let the Javascript and flash code interact with this APIs.


This entry was posted in Technical. Bookmark the permalink.