Actionscript in IE getBytesTotal( ) gotcha

With a recent update either in IE8 or within the Flash Player, I noticed a lot of our AS2 Flash sites that load external assets were failing; either the asset wouldn’t load or it wouldn’t properly report its EVENT_LOADED event. It was happening sporadically, and usually when a lot of external assets were being loaded at the same time.

When I looked into this further I found this line of code within the “run” function that executes on an interval:

if (mc_clip.getBytesTotal( ) < 0)
{
        // failed to load
        bool_isLoaded = false;
        clearInterval( int_interval );
        dispatchEvent( new Event( this, EVENT_FAILED ) );
}

To fix it, I simply added a counter. It now checks to see if getBytesTotal( ) returns negative 10 times before finally reporting EVENT_FAILED.

However, in IE, mc_clip.getBytesTotal( ) is returning a negative number - even though the clip exists and is still loading!

Updating this code to include a wait counter to make sure this the number is still negative after 10 tries seems to have fixed it.

if (mc_clip.getBytesTotal( ) < 0)
{
    if (int_wait > 10)
    {
        // failed to load
        bool_isLoaded = false;
        clearInterval( int_interval );
        dispatchEvent( new Event( this, EVENT_FAILED ) );
    }
    int_wait++;
}

Meta content-type tag does matter!

When editing several files for a French web site that contained non-ASCII latin characters I noticed some strange rendering inconsistencies between Safari and Firefox / IE.

Safari was displaying the characters correctly, however Firefox/IE were not. I tried resaving the file in all different encodings from UTF-8, UTF-16, to Western ISO Latin and got very weird results.

Then I noticed a tag that had been in the existing version of the site:

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

Even though my file was saved as UTF-8, this tag was confusing Firefox and IE into rendering my character data incorrectly. Interestingly, Safari was able to look at the actual file encoding and ignore this meta information.

To fix it all it took was making sure the file was saved as UTF-8 and then making sure the meta tag reflected this:

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

If you encounter strange character rendering then give this a try!

Howto: View Ajax-generated source in IE

Today, Jordan and I were trying to view a piece of rendered source in IE that was put into a div via Ajax. I Googled “IE View Ajax source” and figured I might find an add-in to IE or something that would accomplish this. The first link I found said all that you needed to view this was paste the following code into the address bar in IE:

javascript:'' + window.document.body.outerHTML+ ''

Or you can use this bookmarklet (Drag to links bar or add to Favorites): View Generated Source.

I know, I didn’t believe it would work either but it does work. The HTML that it outputs though is very, very scary.

The page where I found this is here: http://ericappel.net/blog/2006/10/03/ViewHTMLSourceGeneratedByAJAX.aspx

In addition, apparently Microsoft makes a developer toolbar for IE (7 not 8) that you can download as well. Microsoft Developer Toolbar.