Flash IFRAME Integration

Load the ActionScript 3 API from your Flash game externally hosted in an IFRAME

Kongregate API Integration for Flash IFrame Games

In order to use the Kongregate Client API in your Flash game when it is hosted in an iframe, you will need to pass some Kongregate-specific Flash variables into your SWF to allow the ActionScript 3 API to be loaded properly.



For best compatibility with all browsers, set your Flash AllowScriptAccess param to "always" when embedding your SWF

Preparing your HTML

In order to pass in the appropriate Flash Variables, your page source will need to be modified slightly. The first step is including some Kongregate Javascript:

<script src='https://cdn1.kongregate.com/javascripts/kongregate_api.js'>

Once this script is loaded, one can access a string of Kongregate Flash variables with the following JavaScript:


This function will return a URL-encoded string, which will end in "&", so you can simply add any custom Flash Variables you need onto the end of it. You must then pass these Flash Variables into your SWF. For more information on how to do this, see this link.

If you are using something like SWFObject to embed your SWF, it might be more convenient to have access to an Object as opposed to a String containing the Flash Variables. This allows you to enumerate the required Kongregate variables and merge them in with your own variables. You can access this object using the flashVarsObject function as shown below:


Basic HTML Example

Here is a very basic example of how to utilize the above information to pass the Kongregate Flash Variables into your SWF. Please note that this example is very crude, and it is more common to use something such as SWFObject or Adobe's tools to embed a SWF.

<script type="text/javascript" src="https://cdn1.kongregate.com/javascripts/kongregate_api.js">

<script language="javascript" type="text/javascript">
  var flashvars = kongregateAPI.flashVarsString();
  var html='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
  html += 'WIDTH="550" HEIGHT="400" id="game"><PARAM NAME="movie" ID="movie" VALUE="http://www.mysite.com/MyGame.swf">';
  html += '<PARAM NAME='AllowScriptAccess' VALUE='always'/>';
  // Add in flashvars
  html += '<PARAM NAME="flashvars" VALUE="' + flashvars + '">';
  html += '<EMBED src="http://www.mysite.com/MyGame.swf" WIDTH="550" HEIGHT="400"';
  html += 'NAME="game" ID="game" TYPE="application/x-shockwave-flash"';
  html += ' PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"';
  html += ' AllowScriptAccess="always"';
  // Add in flashvars
  html += ' FLASHVARS="' + flashvars + '"></EMBED></OBJECT>';

Once your SWF is loaded using these Flash variables, you can load and use the ActionScript 3 API normally.