flashMovie.Play is not a function

霸气de小男生 提交于 2019-12-23 04:49:14

问题


I'm using this code to play a swf with onclick command for an image. On the first click, I receive "flashMovie.Play is not a function" error. On the second click it works, and every time afterwards. Is this a conflict with the order of execution with other elements in the page? What is happening on the first click that makes the second click work properly? (this works in IE but not firefox)

Would putting some sort of timing delay on this possibly help? Any suggestions as to how I could try that?

<script language="JavaScript">
    function getFlashMovieObject(movieName)
    {
        if (window.document[movieName]) 
        {
            return window.document[movieName];
        }

        if (navigator.appName.indexOf("Microsoft Internet")==-1)
        {
            if (document.embeds && document.embeds[movieName])
                return document.embeds[movieName]; 
        }
        else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
        {
            return document.getElementById(movieName);
        }
    }

    function PlayFlashMovie(name)
    {
        var flashMovie=getFlashMovieObject(name);
        flashMovie.Play();     
    }
</script>

回答1:


If your flash movie isn't loaded before your button is clicked, then you might encounter this problem. I don't think any kind of specific timing delay is a good idea; it would be better to figure out what exactly you are waiting for and then implement the correct handler.

For example, if you were waiting for the whole page to load before doing something, instead of having a 1 second delay, implement a document.onload handler, like so:

document.onload = function () {
    //your code here
}

As a side note, you might consider using SWFObject, as it makes your life a lot easier with regards to Flash and JavaScript.



来源:https://stackoverflow.com/questions/11038529/flashmovie-play-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!