I have a requirement to dynamically add flash elements into a page and have FSCommand function properly.
FSCommand is the primary method that Flash gives a programmer to execute scripts within the parent browser.
This requires some shim code to be added as a listener. This listens for script calls from Flash.
According to the Macromedia examples the listener shim must be created using VBScript. So if my flash object has an id of "flashBufferingPlayer" I would require the following VBScript code that could then do a 'call' out to JavaScript.
<script language='vbscript'>
Sub flashBufferingPlayer_FSCommand(ByVal command, ByVal args)
call flashBufferingPlayer_DoFSCommand(command, args)
end sub
</script>
Even though Macromedia have examples that use pure JavaScript they don't seem to work.
So at first glance it seems that the listener must be VBScript.
But there is a serious issue with adding both JavaScript and VBScript dynamically after document.onload is triggered
- Adding script via innerHTML does not work. Testcase.
- Using document.createElement appendChild does not work.
- Using document.write creates a new document.
Luckily Macromedia is wrong - the following Pure JavaScript will work.
<SCRIPT event=FSCommand(command,args) for=flashBufferingPlayer>
flashBufferingPlayer_DoFSCommand(command, args);
</SCRIPT>
And doubly lucky, a script event listener will work when dynamically added using innerHTML.
Sadly it seems that nothing like
flashBufferingPlayer.onfscommand = flashBufferingPlayer_DoFSCommand;
is available.