How to call javascript function from actionscript ? and actionscript from javascript ? – not working in IE 7

I mentioned a way to communicate between javascript and flash placed on a single HTML page in my previous post. I also had some hard time with this Flash Javascript Integration Kit while testing my code on IE 7.

I spent around 2 and half days on this single problem. Call from java script to action script was working fine in Firefox and safari but not working on IE 7. It was kind of funny and irritating that it was working correctly few times (5 out of 50 times).

I figured it out and fixed this thing somehow (I do not know whether it was fixed permanently but it worked for me after that on IE 7). Let me tell how Flash Javascript Integration Kit works for calling flash function from javascript.

Whenever we make call using Flash javascript Integration kit, it embeds a flash movie(very small in size so that you can not notice it on page) with some flashvars. These flashvars are used to contact the original flash movie on the page.

I believe, this is possible because both movies (original and embedded for function call) share same Flash player run time. Let me take an example here. suppose I am trying to call a function call ‘load’ from javascript to action script with argument as an string ‘show success’.

Integration kit (JavaScriptFlashGateway.js) will embed another tiny flash on the page with initial variable flashvars=functionname=load&arg1=show%2Bsuccess (or like this). By default these variables are passed to the flash movie and this embedded movie can call function other movie using unique id (see previous post for understanding the use of Integration kit)

But it was not happening on IE 7. It was unable to call function of action script from java script on IE 7. I took help of IE developer toolbar to figure out what could be the problem with IE 7.

I took many guesses and finally one of them worked after 2 and half days. I was working on the page where main flash was added on the page some where in the middle and then there are few sections of different types of lists. Sizes of lists are variable. For calling function from JS to AS, tiny flash movie is embedded at the end of the document.

My guess was that problem could the distance between two flash movies in HTML DOM. I tried removing list sections so that tiny flash can be embedded relatively near to original flash movie and it worked.

I made some temporary changes in JavaScriptFlashGateway.js so that it can embed tiny flash under a div near to original Flash movie on my page.

Most Commented Posts

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

Nice site try it here.

Leave a comment

(required)

(required)