# ExternalInterface error - \_ is not a function

**URL:** <https://forum.kirupa.com/t/externalinterface-error---is-not-a-function/265469>\
**Category:** flash\
**Created:** [July 9, 2008, 9:33am UTC](https://forum.kirupa.com/t/externalinterface-error---is-not-a-function/265469 "2008-07-09T09:33:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![derm116](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@derm116](https://forum.kirupa.com/u/derm116)\
**Post date:** [July 9, 2008, 9:33am UTC](https://forum.kirupa.com/t/externalinterface-error---is-not-a-function/265469/1 "2008-07-09T09:33:04Z")

</div>

Hi All,

I’m trying to use the External Interface class to communicate between Javascript and Flex so I can create a javascript API to call all my flex functions! I’ve set this up as follows

* * *

## MXML

I call my javascript setUp function and add a callback to my testing function

private function init():void {

```
            //Setting up the CallBacks for API methods
            ExternalInterface.addCallback("testIfWorks", testIfWorks);
            
            //Testing the calls made from the API
            if (ExternalInterface.available) {
                ExternalInterface.call("setUp"); 
            }
            else {    
                Alert.show("Feature requires web browser", 'Error',mx.controls.Alert.OK);
            }

        }

```

* * *

## Javascript

I keep my js stuff in linechart\_api.js. My swf is called main so I have a setUp function as follows:

//Set up a global varibale referencing the SWF and allowing access to the SWF functions  
function setUp() {  
try{  
lineChart = (navigator.appName.indexOf(“Microsoft”)!=-1)?window[“main”]:document[“main”];  
alert(“app initialized”);  
}catch(e){  
alert(“SWF cannot be found”);  
}  
}

I then call the following testing function

function testAPI(){  
try{  
var res = lineChart.testIfWorks();  
return res;

```
}catch( e ) {
    var str_msg;
    str_msg += "Name: " + e.name + "

```

";  
str\_msg += "File Name: " + e.fileName + "

";  
str\_msg += "Line Number: " + e.lineNumber + "

";  
str\_msg += "Message: " + e.message + "

";  
str\_msg += "Stack: " + e.stack + "  
";  
alert( str\_msg );

```
}

```

}

* * *

## HTML Tester

I add in my javascript API file

\<script src=“linechart\_api.js” language=“javascript”\>\</script\>

and have the following function to call my test

\<script language=“JavaScript” type=“text/javascript”\>  
function test(){  
try{  
testAPI();  
}catch( e ) {  
var str\_msg;  
str\_msg += "Name: " + e.name + "

";  
str\_msg += "File Name: " + e.fileName + "

";  
str\_msg += "Line Number: " + e.lineNumber + "

";  
str\_msg += "Message: " + e.message + "

";  
str\_msg += "Stack: " + e.stack + "  
";  
alert( str\_msg );  
}  
}  
\</script\>

and I have a button to test this

\<button onclick=“test()”\>Test\</button\>

When I click the button I get the following error

lineChart.testAPI is not a function

Can anyone see where I’m going wrong here or how I might get it working? I tried adding a timer to the function of 200milliseconds but the same error keeps coming up? Any help really would be greatly appreciated as this is starting to drive me a bit mental!!!

Thanks,  
Derm

---

<div class="post-metadata">

**Author:** ![derm116](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@derm116](https://forum.kirupa.com/u/derm116)\
**Post date:** [July 10, 2008, 9:23am UTC](https://forum.kirupa.com/t/externalinterface-error---is-not-a-function/265469/2 "2008-07-10T09:23:03Z")

</div>

I’m thinking this is an issue with the swf not been fully up and running (or not been fully created) before the initialise function is called! Does anyone know how to ensure that the swf is fully loaded before I make any calls on the javascript side?!
