Dynamic Generation Of Flash Elements that use FSCommand – JavaScript and VBScript do not work via innerHTML

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.

About James McParlane

CTO Massive Interactive. Ex Computer Whiz Kid - Now Grumpy Old Guru.
This entry was posted in JavaScript. Bookmark the permalink.

8 Responses to Dynamic Generation Of Flash Elements that use FSCommand – JavaScript and VBScript do not work via innerHTML

  1. Josh says:

    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!

  2. jay says:

    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!!!!!!!!!!!!!

  3. Linkside says:

    Thank you again. You save my day ๐Ÿ™‚

  4. Ritika says:

    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

  5. HYT says:

    Thank you!!!!!!!!!
    For this question I working form yesterday night to now … The sun has rising …
    Now I could sleep . Thank you again!!!!

  6. ??????? says:

    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!

  7. ''''''' says:

    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!

  8. superzorro says:

    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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s