It must be late, but i'm not seeing the errors of my ways. i'm simply trying to call an AS3 fx from JS. Code:
<script language="javascript">
function getFlashMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}
getFlashMovie('myswf').playASound();
</script>
<div id="flashContent">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="1" height="1" id="myswf开发者_运维技巧" align="middle">
<param name="movie" value="myswf.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="window" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="myswf.swf" width="1" height="1">
<param name="movie" value="myswf.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="window" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
<!--<![endif]-->
<a href="http://www.adobe.com/go/getflash">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</div>
calling the same method within AS3 plays the sound, so I know that the sound plays. The console gives me the following error:
Uncaught TypeError: Cannot call method 'playASound' of undefined
Thanks!!
EDIT RE: PROGRESS...
This is where I'm at now, still having a null object issue:
<head>
<script type="text/javascript">
var flashvars = false;
var attributes = {
id: "sounds",
name: "sounds"
};
var params = {
wmode: "transparent",
menu: "false",
allowScriptAccess: "always",
play: "true"
};
swfobject.embedSWF("file.swf", "flash-sound", "10", "10", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
</script>
</head>
<body>
<div id="flash-sound"><!--<p>Alternative content</p>--></div>
<script>
$(document).ready(function(){
document.getElementById('sounds').playSound();
});
</script>
</body>
and the error is Cannot call method 'playSound' of null
You are getting the undefined because it can't find your swf in the DOM.
Try using this instead of that "getFlashMovie"-thing
document.getElementById('flashObj').playASound();
Don't forget to set the id-attribute of your swf to "flashObj".
Also, I recommend using swfobject to embed your swf into your html:
swfobject.embedSWF("boot.swf", "flash", "100%", "100%", "10.0.0", "assets/swf/expressInstall.swf", flashvars, params, attributes);
var flashvars = {lang: "<?php echo $lang ?>"};
var params = {allowFullScreen : false, allowScriptAccess: "always", bgcolor: "#FFFFFF", wmode: "transparent"};
var attributes = {id:"flashObj"};
精彩评论