Salem's Euphoria

Sharing Experience

Flex & Javascript : Why that won’t work?

Leave a comment

Some tricks to keep in mind while trying to make a Flex application and Javascript communicate between them. Tutorials are available in the official documentation here and here. But you may be in a hurry, and omit some details that may prevent you from achieving what you want. So, either RTFM pretty slowly, or check those features:

That's you'll always get whenyou are in hurry!

  • ExternalInterface.available

You have to  check whether the browser supports the interface by using its available property:

  //make calls
  • Check Browser constraints

The ExternalInterface class requires the user’s web browser to support either ActiveX or the NPRuntime API that is exposed by some browsers for plug-in scripting.

  • Check Embedded SWF ID

Your SWF object is included in the HTML page using the Object tag.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
<strong>id="logon"</strong> width="100%" height="100%" codebase="">

The id and the name mustn’t  contain those characters :   [.-+*/\].  The sample application here is called “logon”.

  • Referencing your SWF Object

Not all browsers reference the swf object in the same way, some you may add a JS function to avoid this browser incompatibility issue:

<script language="javascript">

function getFlexApp(appName) {
if (navigator.appName.indexOf ("Microsoft") !=-1) {
return window[appName];
} else {
return document[appName];


Be sure to make the correct reference to you application, because:


won’t work. You forgot the double quotes :p


That’s the correct way.

  • Make your Flex methods accessible

Inside the Object tag, in the swf object, change the




And in the Flex side, add a callback to your method to be added to the externalInetrface dictionary.


//callFlexMethod is the AS function you want to call from JS



Allow security domain using Security.allowDomain(‘your js domain’) and make concerned functions public accessible via a wrapper function:

public function callFlexMethod():void{
var wrapperFunction:String = "myPrivateMethod";;

private function myPrivateMethod():void{
//some code here

Got it?… Good for you 😉


Author: Salem Ben Afia

Big Data & Java developer Search Engine Architect, Lucene Expert

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s