AS3.0 External Interface: Pass variables to flash using javascript
Copy link to clipboard
Copied
Hello all,
I am looking for a simple and straightfoward example of how I can pass the value of a variable into flash using javascript.
Specifically, I'd like to use javascript to pass the filename of an external video file that I would like to load into my flash movie.
I'd also like to call a function in the SWF that plays the movie once the filename as been passed to the flash movie.
External Inferface looks like the way to go.
I've found a few decent AS2.0 examples, but converting them to AS3.0 has proven difficult and many of the examples are much too complex for what I am trying to do.
If you have any code samples or tutorials showing the HTML/Javascript and the associated actionscript I'd really appreciate it!
Thanks!
Tim
Copy link to clipboard
Copied
if you create a swf (eiTest.swf) and html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>eiTest</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript">
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
}
function f1(value) {
thisMovie("eiTest").jsF(value);
}
</script>
</head>
<body onload="f1('yourfilename.ext');">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="eiTest" width="550" height="400"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
<param name="movie" value="eiTest.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="eiTest.swf" quality="high" bgcolor="#869ca7"
width="550" height="400" name="eiTest" align="middle"
play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>
</object>
</body>
</html>
you can use:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("jsF", asF);
function asF(fileS:String):void{
trace(fileS);
}
Copy link to clipboard
Copied
Thank you kglad! With a little tweaking we got external interface working for us. Thank you for your helpful and timely response!
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
Hello Sir,
Nice tutorials.
but did not wwork in Chrome...
Please help soon as possible.
-G

