开发者

A question to Flash experts from a beginner: the flash object within a web page

开发者 https://www.devze.com 2022-12-16 23:50 出处:网络
Here\'s my explanation of the question: From JavaScript, you need to get a reference to the Flash Player object. There are two basic Flash Player versions that run in the browser: ActiveX and the plu

Here's my explanation of the question:

From JavaScript, you need to get a reference to the Flash Player object. There are two basic Flash Player versions that run in the browser: ActiveX and the plug-in version. The ActiveX version runs natively in Internet Explorer, while the plug-in version is used by the rest of the browsers.

The ActiveX player is controlled by the object tag in an HTML page, and you can retrieve a JavaScript reference using window. objectId where objectId is the value of the id attribute of the object tag. For example, if the object tag's id attribute is example, then the reference to the ActiveX player would be window.example.

The plug-in player is controlled by the embed tag in an HTML page, and you can retrieve a JavaScript reference by using window.document. embedName, where embedName is the value of the name attribute of the embed tag. For example, if the embed tag's name attribute is example, then the reference to the plug-in player would be window.document.example.

And here's the question itself:

Why does the Flash Player Object exist as a window property when embeded via the object tag, while, when embeded via the embed tag, it exists in the window.document property? And what is the most modern way of getting the Flash Player Ob开发者_运维问答ject from within a web page?


The answer is embedded in the question itself. IE uses object tags and hence SWF is a window object when embedded with object tags. Rest of the world uses embed tags and hence SWF is a property of the window.document for them.


Today I got a funny things. I use the common way to embed a flash in my blog.

<object id="flashObject" width="290" height="100" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
    <param name="movie" value="javascriptcallflash.swf" />
    <param name="quality" value="high" />
    <param name="allowScriptAccess" value="always" />
    <embed name="flashObject" width="100%" height="100%" wmode="transparent" allowScriptAccess="always" width="290" height="100" type="application/x-shockwave-flash" src="javascriptcallflash.swf"/>
</object>

And I also use the common way to get the flash reference:

<script type="text/javascript">
    function getFlashMovie(movieName) {   
        var isIE = navigator.appName.indexOf("Microsoft") != -1;
        return (isIE) ? window[movieName] : document[movieName];  
    }
    function CallFlashFun() {
        var textarea = document.getElementById("jsMsg")
        var flashObj = getFlashMovie("flashObject");
        flashObj.asFunction(textarea.value);
    }
</script>

The problem is that after I publish the post. It doesn't work. So I have try to replace window[movieName] to window.document[movieName]. Then it works. It's very weird.

What's the different between window[movieName], document[movieName], and window.document[movieName]?


swfobject.js still does this most reliably. So much so that it's been adopted by Adobe as the default embedding script.

0

精彩评论

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

关注公众号