Why should I care ?!
Check Step by step tutorials at the bottom of this text.
ExternalInterface minimum requirements
The ExternalInterface Class is only available from Flash 8 and above and will work only in Flash Player 8 and above. Also, there is a minimum browser requirement, the supported are:
Windows Internet Explorer 5.0 and above
Firefox 1.0 and above
Mozilla 1.7.5 and above
Netscape 8.0 and above
Safari 1.3 and above.
Opera 9 and above.
And any browser that supports the NPRuntime API.
The static Boolean property ExternalInterface.available will indicate whether the requirements are meet. Check it from within your targeted container / browser.
Click on the button, if it’s ‘false’ then your browser is probably not supported, if it’s ‘undefined’ then your player is probably less then version 8, if it’s ‘true’ you’re ready to go!
[kml_flashembed movie="http://blog.guya.net/wp-content/uploads/2006/06/ExternalInterface_available.swf" height="90" width="290" /]
Easier to setup:
<param name=”allowScriptAccess” value=”always” /> to support firefox and alike change also the <embed> tag: allowScriptAccess=”sameDomain” to “always”.
If you’re using swfobject your script will look something like this:
so.addParam(“allowScriptAccess”, “always”);. This also won’t guaranty that your files will work locally in all cases, though. You might also need to go to the Flash Player Setting Menager and add the swf files or folder as trusted. Here is a video demo on how to do that.
Multiple Data types:
ExternalInterface supports, sending and receiving, arguments of type: Boolean, String, Number, Array, Object (user defined classes are not supported). Sorry to be dramatic again but this has almost brought tears of joy to my eyes. All this time we had to use nothing more then one lousy String.
How to use the ExternalInterface Class
Calling is easy, Use the static ExternalInterface.call() function.
ExternalInterface.call(“alert”, “called from flash”);
var nValue:Object = ExternalInterface.call(“someJSFunction”);
ExternalInterface.addCallback(“someFlashFunction”, this, someFlashFunction);
“flashMovieID” is the ID of the Flash movie object inside the HTML.
If the Flash function returns a value you can retrieve it as follows, as you might guessed:
var oValue = flashMovie.someFlashFunction();
Step by Step Tutorials for ExternalInterface
I will publish some step by step tutorials with in-depth explanation, source code and images in the next posts. I want to keep this post more concise. (or maybe I’m just too lazy right now… )
Among the tutorials will be:
Best way to get browser’s address variables into Flash.
Controlling another Active-X control – creating flash buttons for Windows Media Player or Apple Quicktime.
Creating, a, dynamic Flash website with AJAX.
Download ExternalInterface availability check
The Flash 8 IDE Installation will install two examples of using the ExternalInterface including the fla sources. But, it doesn’t work locally because they forgot to update the html <object> “allowScriptAccess” to “always”. If you want to check these examples locally simply change the word “sameDomain” wherever it appear (change it twice: one for the object param and one for the embed param) to “always” from within the html files. If it’s still doesn’t work go to the Flash Player Setting Menager and add the swf files or folder as trusted. As described above under Easier to setup:
Find the examples here:
In Windows, browse to boot driveProgram FilesMacromediaFlash 8Samples and TutorialsSamplesActionScriptExternalAPI.
â€¢ On the Macintosh, browse to Macintosh HD/Applications/Macromedia Flash 8/Samples and Tutorials/Samples/ActionScript/ExternalAPI.
Adobe wants to make Flash an IDE independent platform. Which means we’ll be able to create Flash RIA websites and application without the need of Adobe Flex Builder, Using the free Flex SDK, free Flex Data Services and any other third party software. Adobe relized that in order to make Flash the dominant force behind the rich web they have to free it from the restraints of any Flash/Flex IDE. And to leave it solely in the hand of the Flash/Flex developer. Adobe wants to make the Flash Platform as standard as HTML is.
FABridge is availble in pre-alpha since march 2006, so there is already some info about it circling around:
Last Friday I saw the online Adobe event “Flex and Ajax – Better Together” with James Ward. While it was mostly about how much superior Flex is from AJAX, he did showed a few integration / FABridge examples.
A similar presentation by Christophe Coenraets is availble here, with some more FABridge examples.
Go here to download FABridge and get some more info about it. Also check this impressive example that only scratch the surface. (require Flash Player 9).