Tuesday, February 13, 2007

Live HTTP Header solved my Sound problem

For Firefox: http://livehttpheaders.mozdev.org/installation.html

For IE: http://www.blunck.se/iehttpheaders/iehttpheaders.html

The HTTP Header contains some of the most useful data a Flash developer can have. It acts like the trace window, except it works when your Flash file lives on a live server. It tells you everything that is being requested and downloaded by your web page, including your Flash movie. For example, if you use the loadSound() method, it will tell you the file being called and whether if it exists. Although the Sound.onLoad() handler might get the job done, it seems weak at it such that it's unable to detect/handle certain server errors, such as a drop in connection or a memory leak in the browser running the Flash movie. This became evident to me in a project I worked on that required me to load multiple external sounds that would play one after another; the Sound.onLoad() handler folded like a bad poker hand. The HTTP Header prompt showed the file getting loaded but Sound.onLoad() never fired. My workaround was to use onEnterFrame to check the size of the file to determine the existence of it. Something simple like this:


    function checkSoundLoaded() {
        if(Sound.getBytesTotal() != undefined){
            if(Sound.getBytesLoaded() >= Sound.getBytesTotal()) {
                delete this.onEnterFrame;
            }
        }
    }
    this.onEnterFrame = checkSoundLoaded;



Of course, the actual code should do more, such that if after a certain number of tries it does not succeed, it should move on. But it should give you the basic idea.

0 comments: