An interesting post about a potential problem when you're developing Flex application that interact with AJAX (both using Flex AJAX Bridge or ExternalInterface). In Comtaste we're working in a portal that uses a Flex mashup with Google Maps. So we had to find a solution for that :
Creating an ObjectManager for improving the Flex interaction with Ajax or Javascript
The issue is about the access to Flex component just after html loads using body tags
onload attributes while the swf files is not loaded yet.
A possible solution could be the one of waiting a few seconds by using the Javascript function setTimeout(code,millisec,lang)
, however what assures the movie will be ready in that time? If the
movie were not ready, either an error is generated or the input to the
Flex component goes lost.
The solution we followed was to create an ObjectManager in Javascript to handle with the complete loading of the swf file.






















To handle this issue, we use a flash variable containing the name of the JS function that has to be called after the SWF is loaded and inited (FlashVars="onInit=myFunction").
This is the only FlashVar needed (all further params and calls are implemented using FABridge).
Why any more complicated solution?
Posted by: Pavel Simek | July 09, 2007 at 12:35 AM
Your solution works well when you want to call a Javascript function on a Flex event.
In the case of "onload" event it is possible to use your solution because JS always starts earlier then flash movie.
But in our context your approach does not work.
In fact if you have a Javascript event (i.e. onmousedown on an HTML button) that needs to call an Actionscript 3 method,
you don't know if the swf movie has been already loaded.
The solution of using an ObjectManager, that I'll share with you soon, will solve all the issues.
Posted by: Francesco Rapanà | July 12, 2007 at 11:20 AM