In Flash, preferably in the first frame, put this:
ExternalInterface.addCallback('callFlashFunction', null, yourFlashFunction); function yourFlashFunction (arg1, arg2) { ... }
In your Javascript, you can call through:
var flashObj = document.getElementById ('FlashObjID'); flashObj.callFlashFunction (arg1, arg2);
If your SWF is in a different domain, remember to allow script access through:
<object id="FlashObjID"> ... <param name="allowscriptaccess" value="always" /> ... </object>
Update (based on your HTML):
<a href="#" onclick="return jsLoadSong('2')">Play song 2</a> <object id="VSPLAYER" type="application/x-shockwave-flash" data="vs_player.swf" width="280" height="90"> <param name="movie" value="vs_player.swf" /> <param name="allowscriptaccess" value="always" /> </object> <script type="text/javascript"> var flashObj = document.getElementById ('VSPLAYER'); function jsLoadSong (val) { flashObj.loadSong (val); return false; </script>
I tried to clarify the names to show what is in Javascript and which is attached to Flash. Also note that you need to wait for the DOM to load before flashObj definition. here the <script> is after the <object> , so it will work fine.
source share