ExternalInterface.call not doing anything

Posted on 2009-05-01
Medium Priority
Last Modified: 2013-11-11

Here is my issue.  I am trying to use ExternalInterface.call with Javascript injection to change the size of a DIV containing a flash movie every time the menu expands.  However, I am having extreme amounts of trouble with ExternalInterface.  I have set up a test file to check if I was just writing it wrong, but even that doesn't work.  Please take a look at my code and tell me what stupid mistake I am making.  The code I posted is EVERYTHING in my test file.  This is a very big problem for me (delaying production) and is thus worth 500 points to the person with the working answer.

Thanks! - Josh-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="550" height="400">
    <param name="movie" value="test.swf">
    <param name="quality" value="high">
    <embed src="test.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="550" height="400"></embed>
import flash.external.ExternalInterface;

Open in new window

Question by:Deester4x4jr
  • 3
  • 3
  • 3

Expert Comment

ID: 24279205
You are missing the javascript code that is generated by the external interface constructor. Publish you Actionscript file and make sure you generate the HTML that goes with it when publishing. Then either use that HTML code or at least grab the important parts and put them in your HTML page.

The part you are missing looks like this:

But you have to generate your own "AC_RunActiveContent.js" file and have it in the same directory as your actionscript file. The AC file is generated when you publish your AS file.

<script src="AC_RunActiveContent.js" language="javascript"></script>
<script language="javascript">
   if (AC_FL_RunContent == 0) {
      alert("This page requires AC_RunActiveContent.js.");
   } else {
         'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
         'width', '900',
         'height', '700',
         'src', 'javascript_test',
         'quality', 'high',
         'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
         'align', 'middle',
         'play', 'true',
         'loop', 'true',
         'scale', 'showall',
         'wmode', 'window',
         'devicefont', 'false',
         'id', 'javascript_test',
         'bgcolor', '#ffffff',
         'name', 'javascript_test',
         'menu', 'true',
         'allowFullScreen', 'false',
         'movie', 'javascript_test',
         'salign', ''
         ); //end AC code

Expert Comment

ID: 24279236
Don't use my code. It will only work for me. You have to generate your own (by publishing your Actionscript file). Then cut and paste the code that gets generated in the HTML output file into your HTML file (the one you are using to display the page).

LVL 22

Expert Comment

ID: 24283124
You need a few more things that what you have right now...

- an "import flash.external.ExternalInterface;" line of code in your AS3
- you need to make sure that your flash embed code specifies an ID so that your javascript can reference it
- you need some javascript functions to do something on the page

something like this...


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

function sendBackToFlash( value {
thisMovie("FlashIDName").functionNameInFlash( value );

function helloWorld( value ){
alert( value );
sendBackToFlash( "hello back" );


the above assumes that you have a function in your Flash document that is named "functionNameInFlash", and also that you have given your embed code an ID of "FlashIDName"

rp / ZA

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 24283333
section25: I am using Dreamweaver to build my HTML, and it automatically spits out the appropriate AC_RunActiveContent script, however the ExternalInterface API still does not launch an alert window on load of the webpage.

rascalpants: Your example seems to slightly over complicate the situation.  Why would I need to call back to Flash when I want Flash to control the Javascript.  Also, why would I create a function to do an alert, when the object is to inject an alert command into my html page with no pre-existing javascript?

LVL 22

Expert Comment

ID: 24283625
I think you are misunderstanding what ExternalInterface does, or more importantly the power of the class...  it is not a way to avoid having javascript in the HTML... it is a way to talk back and forth between Flash to JS...

the first parameter in the ExternalInterface call is the name of the Javascript function, and the second is the value passed...   so this means you need to have a function with that first parameters name in the HTML or it will not work.  Obviously "alert" works fine without setting up any custom fuction because it is a native javascript method... but I am pretty sure you are going to do a lot more than just call an alert box right?

my example is the basic controls that allow for a "round trip" execution...  I added the other part, just in case you needed to talk back to the Flash player...  call it a bonus ;)

rp / Zone Advisor

Author Comment

ID: 24283809
I appreciate the "bonus" and your input.  But the fact of the matter is, alert isn't working.  It's not doing anything.  I can't get a box to pop-up or anything.  I tried linking it to a button click in the flash movie,and still nothing.  I can't get my Flash ExternalInterface command to call alert AT ALL.  Does this only work when executed over an HTTP connection?  Or should it be working locally like I am trying it?

Thanks again!

Accepted Solution

section25 earned 1000 total points
ID: 24284696
What do you mean by locally? It probably won't work outside of a web page if that is what you mean? It doesn't have to go over a network, but if you are testing the page inside of dreamweaver, then it probably won't work. I don't use DW, so I don't know how it interacts with the browser when testing a page, but try this:

Forget about Dreamweaver for a minute. Create the flash file in the Flash IDE (authoring environent). Inside your AS code, have the call to the alert box in javascript. Publish your flash file along with the HTML code. Run the HTML code that is produced from the Flash publishing exactly as it is (except you need to add the function for the alert call). The javascript should work. Then take that and start with that as the base for your HTML page. You will have it working with everything you need. Then you can just add to it. Just don't change or remove the stuff that was put in there by Flash.
LVL 22

Assisted Solution

rascalpants earned 1000 total points
ID: 24288236
so all u wanted was to have an alert box say hello???  

then yeah...  just use ur exact code you have, and publish from the IDE...

i am suprised you have not tried that already...  

also, yes you will get a secureity sandbox error thrown(only can see with debug player) if u try to run it locally, without setting up a localhost web server first.

if u need a quick solution for a local web server, google WAMP server... it is a one install solution.

fyi...  i copied and pasted ur exact code above, published from flash, and viewed with wamp, and it worked fine.

rp / za

Author Closing Comment

ID: 31576797
Sorry for the delay.  I am giving you both 250 points because you both basically had the same answers and you both put a decent amount of time into it.  I really appreciate the help.  I have decided, because of the uncertainty of ExternalInterface, that I am going to build the whole site in flash, and make the stage height dynamic.  Thanks!

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question