With ExternalInterface class, we can now call any Javascript function that is written on the HTML page or even inside the flash file itself. ExternalInterface is similar in functionality to the fscommand() but is recommended for Javascript-Actionscript communication.
In the example below, i wrote the javascript function inside the flash file inside instead of on the HTML page. Next, i use the ExternalInterface.call method to execute the javascript function and pass the variable back into a actionscript function.
One important condition that you need to set in order to work is you had to give an id value to the flash object tag in the HTML file: