Blog to discuss Midnight Coders products features, ideas and trends in development of Rich Internet Applications

Tuesday, September 13, 2005

Problems with Flash / JavaScript Integration kit

We have been experimenting with the Flash / JavaScript Integration Kit. In overall it is a fairly decent implementation, but we ran into several issues with it:

  • The page that describes how to invoke an ActionScript function from JavaScript shows the following example:
    var tag = new FlashTag('flashContent.swf',300,300,'7,0,14,0');
    // the addFlashVar cannot be found
    tag.addFlashVar('lcId', uid);
    tag.setId('myFlashContent');
    tag.write(document);


    The problem is that the addFlasVar function is not even available in the FlashTag class. Neither is the 'version' argument of the constructor. The proper way to register the lcId variable is:

    tag.setFlashvars( "lcId=" + uid );

  • The way the kit invokes ActionScript functions is by loading the 'gateway' flash movie and passing a query string with the name of the function and all encoded arguments in the flashvars. The problem with that approach, of course, is if JavaScript makes subsequent ActionScript calls back-to-back, only the last one is executed. It is similar to the issue #6 in the list of Known Issues. The root cause of the problem is FlashProxy.js:

    if(!document.getElementById(divName))
    {
    var newTarget = document.createElement("div");
    newTarget.id = divName;
    document.body.appendChild(newTarget);
    }
    // multiple consecutive calls will be modifying the same DIV
    var target = document.getElementById(divName);
    var ft = new FlashTag(this.proxySwfName, 1, 1);
    ft.setVersion('6,0,65,0');
    ft.setFlashvars(qs);
    target.innerHTML = ft.toString();


    One possible workaround is to push JS-to-AS invocations onto a stack and have a timer that checks the stack and then invokes all the functions on from it one by one. If someone has a simpler solution, please let us know.

3 Comments:

Anonymous mike chambers said...

>tag.addFlashVar('lcId', uid);

Hi, the docs are kind of wrong here. The latest version of the code in the source uses this new syntax. The next full release will also use that syntax.

>The problem with that approach, of course, is if JavaScript makes subsequent ActionScript calls back-to-back, only the last one is executed.

This has also been addressed in the latest version of the source, and will be in the next release.

You can find out how to get the latest version of the source here:

http://www.osflash.org/doku.php?id=flashjs:docs:getsource

Thanks for checking out the kit...

mike chambers

mesh@macromedia.com

7:43 AM

 
Blogger Christian Cantrell said...

To expand on what Mike wrote, the problem here is that you are using a very old version of the code. In fact, it looks like you are probably using the very first release. We've made several changes since then (added a great deal of functionality, fixed a ton of bugs, and even changed the API slightly), but we haven't packaged it up into another official release just yet. We will likely do that next week, after the most recent code has been better tested.

You should definitely use the code at the URL Mike provided. It's much more robust, and it address all these issues and many more.

Christian Cantrell

10:18 AM

 
Anonymous Anonymous said...

Hey Mike - the link you posted says:

This topic does not exist yet
You’ve followed a link to a topic that doesn’t exist yet. If permissions allow, you may create it by using the Create this page button.

I have seen alot of broken links out there oin this topic lately however... are you guys getting ready to release maybe?

The kit works great for me, but have a problem with the clicking sound being generated in IE only (when you call out to js).

1:33 PM

 

Post a Comment

<< Home