Blkhwks19
01-11-2012, 06:20 PM
Im attempting to call an AS3 function from JS, but its not working. Ive scoured the internet for days and Ive found lots of tutorials and instructions how to do this, but none of them have worked for me. So Im suspecting it might be something to do with my exact setup. Here's my code.
AS code:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("testFunc", testFunc);
public function testFunc(msg:String):void
{
output.text = msg;
}
HTML/JS/SWFObject embed code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="../scripts/swfobject.js"></script>
<script type="text/javascript">
function getFlashMovie(movieName)
{
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}
var flash = getFlashMovie("flash");
flash.testFunc("hello from JS");
var flashvars = {
// custom flashvars here
};
var params = {
allowscriptaccess: "always",
scale: "noscale",
menu: "false"
};
var attributes = {
id: "mySWF",
name: "mySWF"
};
swfobject.embedSWF("../flash/mySWF.swf", "flash", "550", "400", "9.0.0", null, flashvars, params, attributes);
</script>
</head>
<body>
<div id="flash"></div>
</body>
</html>
Ive tried every method I can find and think of, and absolutely nothing. Can anyone please take a look at what I've got an let me know if I'm missing something or implementing something incorrectly? Thanks SO much in advance!!!
AS code:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("testFunc", testFunc);
public function testFunc(msg:String):void
{
output.text = msg;
}
HTML/JS/SWFObject embed code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="../scripts/swfobject.js"></script>
<script type="text/javascript">
function getFlashMovie(movieName)
{
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}
var flash = getFlashMovie("flash");
flash.testFunc("hello from JS");
var flashvars = {
// custom flashvars here
};
var params = {
allowscriptaccess: "always",
scale: "noscale",
menu: "false"
};
var attributes = {
id: "mySWF",
name: "mySWF"
};
swfobject.embedSWF("../flash/mySWF.swf", "flash", "550", "400", "9.0.0", null, flashvars, params, attributes);
</script>
</head>
<body>
<div id="flash"></div>
</body>
</html>
Ive tried every method I can find and think of, and absolutely nothing. Can anyone please take a look at what I've got an let me know if I'm missing something or implementing something incorrectly? Thanks SO much in advance!!!