Quantcast

« Professional CSS: Cascading Style Sheets for Web Design Unique, Random, Serial Movies, Image Loader »

Flash Player 8 - ExternalInterface

Pre Flash Player 8 Era

In the times before the dawn of the Flash Player 8, Flash-Javascript communication, interaction was done with methods like, SetVariable and GetVariable. The technique however is not that browser-proof in some cases, and is a bit slow too. Nonthless, with the release of the Flash Javascript Integration Kit, it makes it possible to somehow seamlessly communicate between Flash and JavaScript. You can call JavaScript functions from Flash, and ActionScript functions from JavaScript.

In the time of Flash Player 8

Then, came Flash Player 8 and specifically ExternalInterface class; flash.external.ExternalInterface which extends Object. Now the entire approach of Flash-Javascript communication is realizing to a new awakening. The ExternalInterface enables straightforward communications between ActionScript and the Flash Player’s contrainer (for instance, the HTML page with Javascript or a C#, C++ or a Java wrapper). We can safely say that the olden days method of FSCommand() is replaced.

ActionScript - JavaScript

  • to invoke custom ActionScript functions from JavaScript and vice versa and that too with a much cleaner API
  • pass primitive (number, boolean, string) or complex (array, object, etc) data between ActionScript and JavaScript
  • function calls are synchronous and makes you feel as if you are invoking the functions withing same scripting engine (if you invoke a JavaScript function from ActionScript you get the return values instantly, same is true if you invoke ActionScript function from JavaScript).

    For example

Let us look at the following sample codes.
Considering addInJS(…) is a function in JavaScript and addInAS(..) is the one in ActionScript.

//in ActionScript
function addInJS()
{
  var len:Number = arguments.length;
  var result:Number = 1;
  for(var i = 0;  i 

Comments

  1. cucu | July 4th, 2006 | 9:29 am

    this seems very complex code, make things much easier, plz!

Post a comment