The following example shows how you can check to see whether your Flex application is in a container that supports the ExternalInterface API.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/10/checking-to-see-if-the-externalinterface-api-is-available-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
creationComplete="init();">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function init():void {
if (ExternalInterface.available) {
ExternalInterface.call("alert",
"ExternalInterface is available");
} else {
Alert.show("ExternalInterface is not available");
}
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:Button id="button"
label="ExternalInterface.available"
click="init();" />
</mx:ApplicationControlBar>
</mx:Application>
View source is enabled in the following example.





Mmmh, disabling Javascript should disable the external interface, right?
However, if I do so, I don’t get the Flex Alert. Of course I also don’t get the Javascript alert, too. Have I got this wrong or is there an issue with the example?
Thanks!
Klaus
Klaus,
As it turns out, I was unclear/confused on what the ExternalInterface.available property actually does.
From the docs:
I’ll try and update the entry later today and find a better solution (since as you point out, the Flex Alert is pretty much impossible). :)
Peter
OK, I was thinking of this problem over lunch and think I have two possibilities:
1) In your HTML template (/html-template/index.template.html), pass a variable “jsEnabled” using FlashVars in the <noscript /> block. Then, in your Flex application, check for the existance of the jsEnabled variable in Application.application.parameters. If it exists, the <noscript /> block embedded the SWF and the user’s JavaScript is disabled.
2) In your Flex app, try calling ExternalInterface.call(”Date”). If JavaScript is enabled and ExternalInterface is working, you should get the current date/time from JavaScript. If JavaScript is disabled or ExternalInterface is not available, you should get “null” back.
I’ll do a bit more testing after work tonight and update the entry.
Sorry again for the confusion,
Peter
Popup worked, thanks for sharing the information :-)
Seems to be working fine. Looks pretty easy to work with.
worked for me!