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.
Just wanted to say THANK YOU for this entry. I’ve been pulling hair for the last few hours trying to figure out how Macromedia and others were giving me code examples that didnt work.
Anyway, works great now, thanks again!
THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOUTHANK YOU THANK YOUTHANK YOU THANK YOUTHANK YOU THANK YOUTHANK YOU THANK YOU!!! YOU ROCK!!!!!!!!!!!!!
Thank you again. You save my day ๐
i tried using ur methof too but isnt working for me ..plz help…hav been scratching my head since 3 days now
dunno why but the script appends fine to the target but fscommand still doesnt work
plz help fast !
thanx
Thank you!!!!!!!!!
For this question I working form yesterday night to now … The sun has rising …
Now I could sleep . Thank you again!!!!
Thx, man. I was digging last 3 days trying to find this solution. Great idea, but where did you find this event??? I found something like this on macromedia’s site, but … hesitate to try it :-\
BTW: using this ‘<script event=… ‘ there is no need to use vbscript any more for IE ๐
THX one more time and good luck!
Thx, man. I was digging last 3 days trying to find this solution. Great idea, but where did you find this event”’ I found something like this on macromedia’s site, but … hesitate to try it :-\
BTW: using this ‘<script event=… ‘ there is no need to use vbscript any more for IE ๐
THX one more time and good luck!
Hello,
i just tried your script to get a script running wich uses innerHTML and onload. It works pretty well in IE but i doesn’t work in Firefox at all. Is there a way to get it running in FF as well?
chers
uli