{"_id":"571112b36def262b003bb5f0","version":{"_id":"56abbf55f25f160d00e17f51","project":"56abbf55f25f160d00e17f4e","__v":12,"createdAt":"2016-01-29T19:36:53.665Z","releaseDate":"2016-01-29T19:36:53.665Z","categories":["56abbf56f25f160d00e17f52","56abca6bf9757e0d007c6650","56acddfa0ab3c00d00ce3332","56af65da9d32e30d0006d30f","56af66cab34d210d003d9ad0","56af6afcd21e9c0d00b628d1","56af6d6ecc4cbd0d00ce2c88","5705b12221cfed0e00e8c580","570a5676ade45d0e00c1ad33","570d7d25d1e4b82000d9e385","570eac3c3160d10e0041df0e","575709000fd6a3200010dded"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":8,"category":{"_id":"575709000fd6a3200010dded","project":"56abbf55f25f160d00e17f4e","__v":0,"version":"56abbf55f25f160d00e17f51","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-06-07T17:48:48.065Z","from_sync":false,"order":0,"slug":"test","title":"Platform Overview"},"user":"56abbec30b9e0b0d00616274","parentDoc":null,"project":"56abbf55f25f160d00e17f4e","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-04-15T16:11:31.544Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":6,"body":"### Kongregate API Integration for Flash IFrame Games\n\nIn order to use the [Kongregate Client API](doc:client-api-introduction) 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](doc:actionscript-3-api) to be loaded properly.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Note\",\n  \"body\": \"For best compatibility with all browsers, set your Flash AllowScriptAccess param to \\\"always\\\" when embedding your SWF\"\n}\n[/block]\n### Preparing your HTML\n\nIn 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:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<script src='https://cdn1.kongregate.com/javascripts/kongregate_api.js'>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nOnce this script is loaded, one can access a string of Kongregate Flash variables with the following JavaScript:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"kongregateAPI.flashVarsString();\",\n      \"language\": \"javascript\",\n      \"name\": null\n    }\n  ]\n}\n[/block]\nThis 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](http://kb2.adobe.com/cps/164/tn_16417.html).\n\nIf 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:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"kongregateAPI.flashVarsObject();\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n### Basic HTML Example\n\nHere 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.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<body>\\n<script type=\\\"text/javascript\\\" src=\\\"http://www.kongregate.com/javascripts/kongregate_api.js\\\">\\n</script>\\n\\n<script language=\\\"javascript\\\" type=\\\"text/javascript\\\">\\n  var flashvars = kongregateAPI.flashVarsString();\\n  var html='<OBJECT classid=\\\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\\\"' +\\n 'codebase=\\\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\\\"';\\n  html += 'WIDTH=\\\"550\\\" HEIGHT=\\\"400\\\" id=\\\"game\\\"><PARAM NAME=\\\"movie\\\" ID=\\\"movie\\\" VALUE=\\\"http://www.mysite.com/MyGame.swf\\\">';\\n  html += '<PARAM NAME='AllowScriptAccess' VALUE='always'/>';\\n  // Add in flashvars\\n  html += '<PARAM NAME=\\\"flashvars\\\" VALUE=\\\"' + flashvars + '\\\">';\\n  html += '<EMBED src=\\\"http://www.mysite.com/MyGame.swf\\\" WIDTH=\\\"550\\\" HEIGHT=\\\"400\\\"';\\n  html += 'NAME=\\\"game\\\" ID=\\\"game\\\" TYPE=\\\"application/x-shockwave-flash\\\"';\\n  html += ' PLUGINSPAGE=\\\"http://www.macromedia.com/go/getflashplayer\\\"';\\n  html += ' AllowScriptAccess=\\\"always\\\"';\\n  // Add in flashvars\\n  html += ' FLASHVARS=\\\"' + flashvars + '\\\"></EMBED></OBJECT>';\\n  document.write(html);\\n</script>\\n</body>\\n</html>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nOnce your SWF is loaded using these Flash variables, you can load and use the [ActionScript 3 API](doc:actionscript-3-api) normally.","excerpt":"Load the ActionScript 3 API from your Flash game externally hosted in an IFRAME","slug":"concepts-flash-iframe-integration","type":"basic","title":"Flash IFRAME Integration"}

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](doc:client-api-introduction) 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](doc:actionscript-3-api) to be loaded properly. [block:callout] { "type": "info", "title": "Note", "body": "For best compatibility with all browsers, set your Flash AllowScriptAccess param to \"always\" when embedding your SWF" } [/block] ### 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: [block:code] { "codes": [ { "code": "<script src='https://cdn1.kongregate.com/javascripts/kongregate_api.js'>", "language": "html" } ] } [/block] Once this script is loaded, one can access a string of Kongregate Flash variables with the following JavaScript: [block:code] { "codes": [ { "code": "kongregateAPI.flashVarsString();", "language": "javascript", "name": null } ] } [/block] 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](http://kb2.adobe.com/cps/164/tn_16417.html). 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: [block:code] { "codes": [ { "code": "kongregateAPI.flashVarsObject();", "language": "javascript" } ] } [/block] ### 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. [block:code] { "codes": [ { "code": "<body>\n<script type=\"text/javascript\" src=\"http://www.kongregate.com/javascripts/kongregate_api.js\">\n</script>\n\n<script language=\"javascript\" type=\"text/javascript\">\n var flashvars = kongregateAPI.flashVarsString();\n var html='<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"' +\n 'codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\"';\n html += 'WIDTH=\"550\" HEIGHT=\"400\" id=\"game\"><PARAM NAME=\"movie\" ID=\"movie\" VALUE=\"http://www.mysite.com/MyGame.swf\">';\n html += '<PARAM NAME='AllowScriptAccess' VALUE='always'/>';\n // Add in flashvars\n html += '<PARAM NAME=\"flashvars\" VALUE=\"' + flashvars + '\">';\n html += '<EMBED src=\"http://www.mysite.com/MyGame.swf\" WIDTH=\"550\" HEIGHT=\"400\"';\n html += 'NAME=\"game\" ID=\"game\" TYPE=\"application/x-shockwave-flash\"';\n html += ' PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\"';\n html += ' AllowScriptAccess=\"always\"';\n // Add in flashvars\n html += ' FLASHVARS=\"' + flashvars + '\"></EMBED></OBJECT>';\n document.write(html);\n</script>\n</body>\n</html>", "language": "html" } ] } [/block] Once your SWF is loaded using these Flash variables, you can load and use the [ActionScript 3 API](doc:actionscript-3-api) normally.