0
import flash.external.ExternalInterface;

//ExternalInterface.call("alert", "what");
ExternalInterface.call("show_alert");

HTML CODE

<script type="text/javascript">
function show_alert() {
 alert('no');   
}
</script>


<div id="flashContent">
        <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" id="test" align="middle">
            <param name="movie" value="test.swf" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#999900" />
            <param name="play" value="true" />
            <param name="loop" value="true" />
            <param name="wmode" value="window" />
            <param name="scale" value="showall" />
            <param name="menu" value="true" />
            <param name="devicefont" value="false" />
            <param name="salign" value="" />
            <param name="allowScriptAccess" value="sameDomain" />
            <!--[if !IE]>-->
            <object type="application/x-shockwave-flash" data="test.swf" width="550" height="400">
                <param name="movie" value="test.swf" />
                <param name="quality" value="high" />
                <param name="bgcolor" value="#999900" />
                <param name="play" value="true" />
                <param name="loop" value="true" />
                <param name="wmode" value="window" />
                <param name="scale" value="showall" />
                <param name="menu" value="true" />
                <param name="devicefont" value="false" />
                <param name="salign" value="" />
                <param name="allowScriptAccess" value="sameDomain" />
            <!--<![endif]-->
                <a href="http://www.adobe.com/go/getflash">
                    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                </a>
            <!--[if !IE]>-->
            </object>
            <!--<![endif]-->
        </object>
    </div>
  • 1
    It's possible that you're calling the javascript function before the DOM has been fully loaded. Try calling it a bit later: `setTimeout(function(){ExternalInterface.call("show_alert"");}, 1000);` – Sunil D. Aug 07 '12 at 16:36
  • thanks for your comments, I tried this through a button actually but still not working –  Aug 08 '12 at 10:40

1 Answers1

1

If you are creating a file using AS2 then try this : _root.getURL("javascript:show_alert();"); instead of ExternalInterface.call("show_alert");

If you are using the AS3 then the code is perfect, no need to change.

Due to some security features Flash Player can not communicate with the javascript locally. If you run the same files on the live server or localhost, it will work.