flashMovie.Play is not a function

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>

Answers:

Answer

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.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.