# externalInterface, swfObject, and you

**URL:** <https://forum.kirupa.com/t/externalinterface-swfobject-and-you/287643>\
**Category:** web dev\
**Created:** [May 4, 2009, 5:12pm UTC](https://forum.kirupa.com/t/externalinterface-swfobject-and-you/287643 "2009-05-04T17:12:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Goth\_Santa](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Goth\_Santa](https://forum.kirupa.com/u/Goth_Santa)\
**Post date:** [May 4, 2009, 5:12pm UTC](https://forum.kirupa.com/t/externalinterface-swfobject-and-you/287643/1 "2009-05-04T17:12:53Z")

</div>

Interesting problem (and of course by “interesting” I mean “frustrating”).

I’m using SWFObject to display a flash movie, and that’s fine. Now I’m trying to use external interface to pass a variable via JavaScript.

Here’s the JavaScript code:

```auto

<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">

swfobject.registerObject("tab", "9.0.0");

window.onload = function () {
   var swf = swfobject.getObjectById("tab");
   swf.asFunc("10");
}

</script>

```

Now I get one of two errors (seems to be random): “swf.asFunc is not a function” or “uncaught exception: Error calling method on NPObject! [plugin exception: Error in Actionscript. Use a try/catch block to find error.].”

Here’s my ActionScript (on frame 1 of the root of the .swf):

```auto

import flash.external.ExternalInterface;
ExternalInterface.addCallback("asFunc", this, asFunc);
function asFunc(str:String):Void {
    widthBox.text = str;
}

```

What am I missing?
