开发者

swfobject not communicating with html

开发者 https://www.devze.com 2023-03-14 17:37 出处:网络
I\'m having trouble trying to get swfobject embedded files to communicate with my html. When I embed swfs the the standard way using AC_RunActiveContent it works, any ideas why this would be ? Basical

I'm having trouble trying to get swfobject embedded files to communicate with my html. When I embed swfs the the standard way using AC_RunActiveContent it works, any ideas why this would be ? Basically the navigation buttons along the bottom stop the swfs from playing when their clicked. I'd really appreciate any help!

<script type="text/javascript" src="js/swfobject.js"></script>

<script type="text/javascript">
var flashvars = {};
var params = {};
params.play = "true";
params.loop = "false";
params.menu = "true";
params.quality = "high";
params.scale = "showall";
params.wmode = "opaque";
params.bgcolor = "#ffffff";
params.devicefont = "false";
params.allowscriptaccess = "always";

var attributes = {};
swfobject.embedSWF("images/blank1.swf", "blank1", "747", "420", "9.0.0", flashvars, params, attributes);
swfobject.embedSWF("images/blank2.swf", "blank2", "747", "420", "9.0.0", flashvars, params, attributes);
swfobject.embedSWF("images/blank3.swf", "blank3", "747", "420", "9.0.0", flashvars, params, attributes);
</script>


<script language="javascript">
function getFlashMovie(mov开发者_运维知识库ieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}

function stopFlash(){
    getFlashMovie("blank1").commandFlash();
    getFlashMovie("blank2").commandFlash();
    getFlashMovie("blank3").commandFlash();
}

HTML:

<div>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="747" height="420">
    <param name="movie" value="images/blank1.swf" />
    <!--[if !IE]>-->
    <object type="application/x-shockwave-flash" data="images/blank1.swf" width="747" height="420">
    <!--<![endif]-->
    <img src="images/blank1.jpg" alt="" width="747px" height="420px" />
    <!--[if !IE]>-->
    </object>
    <!--<![endif]-->
    </object>
</div>

<div id="navigation">
<a href="#" name="btn" onClick="stopFlash()"><div id="slideshow-previous"></div></a>
<a href="#" name="btn" onClick="stopFlash()"><div id="slideshow-next"></div></a>
<a href="#" name="btn" onClick="stopFlash()"><div id="slideshow-first"></div></a>
</div>

Thanks for any feedback!


In your SWF, have you imported flash.external.ExternalInterface?

If not, you'll need to do that and then also expose the 'commandFlash' method in your SWF. You may need to allow this kind of communication on your domain, too.

import flash.external.ExternalInterface;

System.security.allowDomain('*');
var flashAvailable:Boolean = ExternalInterface.available;

ExternalInterface.addCallback('commandFlash', null, commandFlash);
function commandFlash( args... ){
  //
}

Other than the above, perhaps your SWF is hidden with display:none; on the page at some point, and then revealed? This has caused some strangeness for me in Firefox in the past.

(not sure if you're using AS2/3 in your SWF)


Your SWFObject code has errors: it's missing the express install parameter.

swfobject.embedSWF("images/blank1.swf", "blank1", "747", "420", "9.0.0", "expressinstall.swf", flashvars, params, attributes);
swfobject.embedSWF("images/blank2.swf", "blank2", "747", "420", "9.0.0", "expressinstall.swf", flashvars, params, attributes);
swfobject.embedSWF("images/blank3.swf", "blank3", "747", "420", "9.0.0", "expressinstall.swf", flashvars, params, attributes);

Of course you need to replace "expressinstall.swf" with the correct path to your expressinstall.swf file. If you don't want to use express install, just put a false boolean instead.

swfobject.embedSWF("images/blank1.swf", "blank1", "747", "420", "9.0.0", false, flashvars, params, attributes);
swfobject.embedSWF("images/blank2.swf", "blank2", "747", "420", "9.0.0", false, flashvars, params, attributes);
swfobject.embedSWF("images/blank3.swf", "blank3", "747", "420", "9.0.0", false, flashvars, params, attributes);


Sorted - managed to work it out (see below) thanks to everyone for their input/support! Only problem now is internet explorer is returning an error "object doesn't support this property or method" on the buttons that fire the stopFlash command, but at least it still works. Grrr.

var flashvars = {};
var params = {wmode:"opaque", allowscriptaccess:"always" };
var attributes = {};

swfobject.embedSWF("images/clients/blank1.swf", "blank1", "747", "420", "9.0.0", false, flashvars, params, attributes);
swfobject.embedSWF("images/clients/blank2.swf", "blank2", "747", "420", "9.0.0", false, flashvars, params, attributes);
swfobject.embedSWF("images/clients/blank3.swf", "blank3", "747", "420", "9.0.0", false, flashvars, params, attributes);


function getFlashMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}


function stopFlash(){
getFlashMovie("blank1").commandFlash();
getFlashMovie("blank2").commandFlash();
getFlashMovie("blank3").commandFlash();
return true;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号