最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - flash fscommands and javascript - Stack Overflow

programmeradmin2浏览0评论

I try get the mp3 flash player to work with my javascript on all browsers. All went well for first, but fast realized that my code doesn't work on MSIE.

After trying to find out I found this in the reference code:

<!--[if IE]>
<script type="text/javascript" event="FSCommand(mand,args)" for="myFlash">
eval(args);
</script>
<![endif]-->

How to turn this into a javascript or jquery clause that I could stuff it where it belongs to (in audio.js)?

I try get the mp3 flash player to work with my javascript on all browsers. All went well for first, but fast realized that my code doesn't work on MSIE.

After trying to find out I found this in the reference code:

<!--[if IE]>
<script type="text/javascript" event="FSCommand(mand,args)" for="myFlash">
eval(args);
</script>
<![endif]-->

How to turn this into a javascript or jquery clause that I could stuff it where it belongs to (in audio.js)?

Share Improve this question edited Nov 11, 2008 at 19:43 Ben Combee 17.4k6 gold badges42 silver badges42 bronze badges asked Nov 11, 2008 at 10:40 CheeryCheery 25.5k16 gold badges61 silver badges83 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 2

That syntax, with the <script> tag with the "event" and "for" attributes is an Internet Explorer-only way of setting up an event handler on an DOM object. Here, it adds a FSCommand event handler to the myFlash object. This is needed because code running inside the Flash object may want to run JavaScript in the browser. To do this, the Flash object will invoke the FSCommand event handler, passing the JavaScript to run as the arguments to the event.

With this player, the name of a JS listener object is passed in the FlashVars param to the player. It then uses FSCommands from ActionScript to modify that listener object, with an occasional call to a method on that listener when it's other properties have been modified. I suppose that IE isn't able to run the JS code using this method until the FSCommand handler has been added to the Flash player object, which is why that code exists. Modify it to use the ID of your Flash object and you should be in good shape.

Maybe this is more about embedding flash dynamically.

I got stuck on exactly the same thing with mp3 flash player. The thing is that IE doesn't care about the special script tag with 'event' and 'for' attribute, if it is added AFTER the page has loaded. My IE wouldn't event eat jquery's .html() when the page loaded, only document.write worked. But document.write can't really be used after the page has loaded, unless it is targeted in an iframe or some other devil worship mechanism.

What's good tho, is that IE doesn't distinguish between assigning an event handler in this bastard script tag or programatically. This means that:

<script type="text/javascript" event="FSCommand(mand,args)" for="myFlash">
    eval(args);
</script>

in IE directly translates to:

function foo(mand, args){
    eval(args);
}
var ie_sucks = document.getElementById('myFlash');
ie_sucks.attachEvent("FSCommand", foo);

And... in the end we have that:

var ie_sucks = document.getElementById('ebacker_audio');
ie_sucks.attachEvent("FSCommand", function(mand, args) {eval(args);});

and if that not work for you, try to check your html for inserting object. Example here: http://kb2.adobe./cps/415/tn_4150.html

;)

Thanks everyone for the above. I'll just drop a few lines that were handy for me.

To re-use code across browsers, do:

<script type="text/javascript">
    function mySwf_DoFSCommand(mand, args) {
        // do stuff
    }
</script>

<!--[if IE]>
<script type="text/javascript" event="FSCommand(mand,args)" for="mySwf">
    mySwf_DoFSCommand(mand, args);
</script>
<![endif]-->
发布评论

评论列表(0)

  1. 暂无评论