Using a custom preloader in AS3 with wmode=transparent
Recently we had trouble with a flash piece for a client. The swf’s we made would not load and just show the loading progress bar. Upon further investigation it turns out we changed the swf to wmode transparent. Now I know from past experiences that flash’s internal timing changes with transparent and normally I recommend it be avoided at all costs, but this is a simple piece, just a little image gallery with some tweens, not a game where fps and timing are important.
Being stuck at the preloader lead me to believe something with the preloader is not acting right in wmode transparent. It turns out the ProgressEvent.PROGRESS event’s are not firing. Why ? I can’t say, but I think Adobe needs to look into wmode transparent as this isn’t the only odd thing that happens.
The fix is to simply use an Event.ENTER_FRAME event to check the preload status rather than a ProgressEvent.PROGRESS, since Event.ENTER_FRAME event’s still fire flawlessly.
Normal preloader code:
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, loading);
var pct:Number = 0;
function loading(event:ProgressEvent):void
{
pct = event.bytesLoaded / event.bytesTotal;
loading.loadedBar.scaleX = pct;
trace(pct);
if(pct >= 1)
{
this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, loading);
gotoAndPlay(2);
}
}
wmode = transparent preloader:
this.addEventListener(Event.ENTER_FRAME, loading);
var pct:Number = 0;
function loading(event:Event)
{
pct = this.loaderInfo.bytesLoaded / this.loaderInfo.bytesTotal
loading.loadedBar.scaleX = pct;
trace(pct);
if(pct >= 1)
{
this.removeEventListener(Event.ENTER_FRAME, loading);
gotoAndPlay(2);
}
}
**** UPDATE 7/26/2010 By Paul ****
I haven't tested it, but looking through the changelog for 10.1 flash player I noticed:
"[FP-1585] loaderInfo Event.COMPLETE not dispatched if wmode is "transparent" or "opaque". (2345794)"
This may be related to the progress bug as well, makes sense, there's just an event dispatch problem in wmode transparent.
Adobe _MAY_ have fixed this bug. That doesn't help the stragglers using old flash versions, but its better then nothing.

