Calling a Flex function from javascript
28 Apr 2005Update: I have updated the content of this entry after it was posted. John Dowdell(JD) pointed out some part of post which were confusing. I hope, it is clear now.
This is quite common question in Flash and Flex world. I had created JSFCommunicator library long back to facilitate JavaScript-Flash-JavaScript communication. But JSFC is supported in applications created via Macromedia Flash authoring tool, it is not straight forward to use it in Macromedia Flex applications. JSFC also has some issues in Firefox browser on MacOS. I am going to update it so that it works well on most of the browsers, operating systems and also in Macromedia Flex applications.
In flexcoders list, someone asked how to call a function in Flex app from Javascript, I wrote a simple example to show the technique. Following example is not a very OO approach, but it can easily be made more reusable by wrapping things into classes or creating a component.
JavaScript Code:
//this function return to Flash ActiveX Object or Plugin depending upon browser //it takes care for browser type and returns the proper reference. //Accepts the id or name of