Friday, October 9, 2009

Flash integration: Always check stage size before you do anything

I had a project to design a Flash component API that needs to be easy to integrate with all video players. I had investigated more than a dozen video players used by web publishers of any size. These video players included big brand names like YouTube and Brightcove, and generic players such as JW and Flowplayers. The goal is simple: the Flash component API needs to work on any given web pages. Making jobs easy for other developers means we have to do all dirty works.

Some web sites have lots of problems in their HTML markups and JavaScripts. Often times, these publishers have no engineering resource to maintain their code. They probably did not test their site performance across different browsers on different platforms. Some bad codes are not fatal but just make the site slow. But for anyone who needs to add code into it, watch out!

More than once, I found my Flash component failed to load on IE. It's always perfect on Firefox. It also happened only on a few sites.

It turned out that this was a timing issue caused by some JavaScripts that IE had problems with. When I initialized my Flash components, the Flash stage size was ZERO! Yes, you don't always get the stage dimension you set in HTML object tag. Solution? I now always add a timer to poll stage width and height till both are not zero before I even initialize any objects in ActionScript. This is a protection for my ActionScript because I have no idea how it will be used by others.

Remember, if your Flash does not work on IE, and IE only, always check if Flash stage size is zero! Before you can fix your JavaScripts and make IE happy, you can always protect your ActionScripts by waiting till Flash stage is properly initialized.

1 comment:

June said...

Hi, Chebin, Eric (Shih-tse) gave me your website, and thereby I found your blog. I was your junior high school English teacher June. Did I surprise you? Well, after so many years.... Eric told me that you are very busy. Remember to stop and smell the roses once in a while. Best wishes. I have a blog too, a very plain one.

http://www.tiec.tp.edu.tw/lifetype/1130