How call JavaScript function from FLASH

We can call the JavaScript function from FLASH application. I am showing here how we do that.

getURL("javascript:helloWorld();");

Here “getURL()” is the Flash ActionScript function. We have give the name of our JavaScript function with “javascript:” as prefix. This will call the “helloWorld()” function which we have defined in JavaScript.

<script type="text/javascript">
     function helloWorld() {
           alert('Hello World');
     }
</script>

Also, add the following parameter to the OBJECT and EMBED tag:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="150" height="120">
  <param name="movie" value="swf/myflash.swf" />
  <param name="allowscriptaccess" value="always" />
  <param name="wmode" value="transparent" />
  <param name="menu" value="false" />
  <embed height="120" width="150" allowscriptaccess="always" wmode="transparent" menu="false" src="swf/myflash.swf" type="application/x-shockwave-flash"/>
</object>

allowscriptaccess let the Flash application to communicate with the HTML page hosting it. This is required because getURL() function can cause JavaScript to use the permissions of the HTML page, which can be different from the permissions of your Flash application. This has important implications for cross-domain security.

The valid values for allowscriptaccess are:

always permits scripting operations at all times.
never forbids all scripting operations.
samedomain permits scripting operations only if the Flash application is from the same domain as the HTML page.

The default value used by all HTML publish templates is samedomain.

,


  1. No comments yet.
(will not be published)

 


Submit Comment
Subscribe to comments feed
  1. No trackbacks yet.