# Using JavaScript to call a function in Flash

**URL:** <https://forum.kirupa.com/t/using-javascript-to-call-a-function-in-flash/232684>\
**Category:** flash\
**Created:** [July 16, 2007, 10:19pm UTC](https://forum.kirupa.com/t/using-javascript-to-call-a-function-in-flash/232684 "2007-07-16T22:19:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Search\_This\_com](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Search\_This\_com](https://forum.kirupa.com/u/Search_This_com)\
**Post date:** [July 16, 2007, 10:19pm UTC](https://forum.kirupa.com/t/using-javascript-to-call-a-function-in-flash/232684/1 "2007-07-16T22:19:09Z")

</div>

I’m trying to use JavaScript to call a function in Flash 8.

My code works in Firefox, but not IE6.

I think it has something to do with the fact that my flash object is in a form? In using SWFObject to add flash in my HTML and it’s in a form.

Here’s the html…

```auto

<form id="form1" name="form1" runat="server">
.
.
.
     <!-- EMBED FLASH OBJECT -->
        <div id="flashcontent">
            If you are reading this then you don't have Flash.
        </div>

        <script type="text/javascript">
         var so = new SWFObject("AdViewer.swf", "AdViewer", "500", "332", "9", "#ffffff");
         so.addParam("quality", "best");
         so.addVariable("AdID", "4");
         so.write("flashcontent");
        </script>
        <!-- EMBED FLASH OBJECT -->
.
.
.
</form>

```

Here’s my javacript

```auto

// JAVASCRIPT

    // tell Flash to set image
    function getAdinFlash( AdID )
    {
        thisMovie("AdViewer").loadAdNow( AdID );
    }
    function thisMovie(movieName) {
        if (navigator.appName.indexOf("Microsoft") != -1) {
            return document.getElementById(movieName);
        } else {
            return document[movieName]
        }
    }

```

and my Flash, any ideas?

```auto

// IN FLASH

//import flash.external.*;
var methodName:String = "loadAdNow";
var instance:Object = this;
var method:Function = loadAd;
var wasSuccessful:Boolean = ExternalInterface.addCallback(methodName, instance, method);

function loadAd(AdID) {
    var imgPath:String = "http://localhost/Extanse/InStoreKioskWeb/flashkiosk/imageresponse.aspx?Type=7&AdID="+ AdID;
    debugger.text = imgPath;
    image_mcl.loadClip( imgPath, imageHolder );
}

```
