{"id":14,"date":"2007-01-27T10:33:01","date_gmt":"2007-01-27T18:33:01","guid":{"rendered":"http:\/\/todepoint.com\/blog\/?p=13"},"modified":"2007-01-27T10:33:01","modified_gmt":"2007-01-27T18:33:01","slug":"communicating-with-flash-external-interface-method","status":"publish","type":"post","link":"https:\/\/todepoint.com\/blog\/2007\/01\/27\/communicating-with-flash-external-interface-method\/","title":{"rendered":"Communicating with Flash &#8211; External Interface method"},"content":{"rendered":"<p>Be warned, I will discuss ActionScript in the following words, you may want to eat something before reading any further. Any way, this may not be &#8220;hot news&#8221; but will still open my ActionScript category :)From time to time when I have more than one flash site open and they play sounds or music, I get confused which window produce what music? Since I am using a Mac where all the windows sounds just blend, it is really hard to tell.I expect flash authors &amp; developers to handle this issue, especially in flash website, by adding a script that will stop the sound in the flash when the window is loosing focus. This is an example of a need for communication between flash and the scripting environment, invoking JavaScript functions from flash and vice versa, actually it&#8217;s also relevant in applications embedding flash player, and maybe <a href=\"http:\/\/labs.adobe.com\/wiki\/index.php\/Apollo\">Apollo<\/a> soon?.<br \/>\nI will start with legacy methods:<br \/>\nThe good old <a href=\"http:\/\/www.adobe.com\/support\/flash\/publishexport\/scriptingwithflash\/scriptingwithflash_03.html\">Flash Methods<\/a> is pretty simple but very limited, all it can do is set\/get a property in the flash object, or send flash few basic commands. The other direction &#8211; invoking JS functions from within Flash was done using <a href=\"http:\/\/www.adobe.com\/support\/flash\/action_scripts\/actionscript_dictionary\/actionscript_dictionary372.html\">fscommand<\/a> that can pass one argument, so by using some kind of formatting (heard of <a href=\"http:\/\/www.json.org\/\">Jason<\/a>?) enabled passing few values in one string. However, fscommand does not return any value to flash, and therefore required using listeners for utilizing in more complex applications.<br \/>\nThe new method:The <a href=\"http:\/\/livedocs.macromedia.com\/flash\/8\/main\/wwhelp\/wwhimpl\/common\/html\/wwhelp.htm?context=LiveDocs_Parts&amp;file=00002200.html\">External Interface<\/a> Class Is a more matured method for communicating between ActionScript and the environment, available for flash version 8 and above, all major browsers.<\/p>\n<p class=\"quoted\"><strong>From ActionScript, you can do the following on the HTML page:<\/strong><br \/>\nCall any JavaScript function, Pass any number of arguments, Pass various data types (Boolean, Number, String, and so on), Receive a return value from the JavaScript function.<br \/>\n<strong>From JavaScript on the HTML page, you can:<\/strong><br \/>\nCall an ActionScript function, Pass arguments using standard function call notation, Return a value to the JavaScript function.<\/p>\n<p>It works by registering a function for external use by the browser, the registration is done using the ExternalInterface class and basically dedicates a unique name for each function.<br \/>\nThis <a href=\"http:\/\/www.todepoint.com\/adi\/as_examples\/ei_example.html\" target=\"_blank\">example<\/a> shows an event (Page loosing\/getting focus) that triggers a function in flash (stop\/play sound), you can <a href=\"http:\/\/www.todepoint.com\/adi\/as_examples\/ei_example.zip\">download sources here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Be warned, I will discuss ActionScript in the following words, you may want to eat something before reading any further. Any way, this may not be &#8220;hot news&#8221; but will still open my ActionScript category :)From time to time when I have more than one&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,15,16,24],"tags":[],"_links":{"self":[{"href":"https:\/\/todepoint.com\/blog\/wp-json\/wp\/v2\/posts\/14"}],"collection":[{"href":"https:\/\/todepoint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/todepoint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/todepoint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/todepoint.com\/blog\/wp-json\/wp\/v2\/comments?post=14"}],"version-history":[{"count":0,"href":"https:\/\/todepoint.com\/blog\/wp-json\/wp\/v2\/posts\/14\/revisions"}],"wp:attachment":[{"href":"https:\/\/todepoint.com\/blog\/wp-json\/wp\/v2\/media?parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/todepoint.com\/blog\/wp-json\/wp\/v2\/categories?post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/todepoint.com\/blog\/wp-json\/wp\/v2\/tags?post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}