Flex - Custom preloader IE stageWidth - stageHeight problem fixed

February 15th, 2008 by Jaap Kooiker

My…my…my…
Internet Explorer is like….bad for your health (but you already know that)

In one of the projects I was working on, we used the custom preloader class by Jesse Warden. This way we were able to define our own preloader and it works great, but ofcours not in IE. The alignment in IE doesn’t seem to work after a refresh - or not even at all. This doesn’t happen in any other respectable browser and when using the default flex html template. But we use SWFObject in our projects and then the problem occurs (again only in IE). For the record…it isn’t a SWFObject problem.

After placing a resize event listener on the stage the following occurs.
For some weird reason IE triggers a Resize event at a point when stage width and height is still zero. And at init both width and height are also zero. These 2 resize events aren’t dispatched in for instance FireFox. So no problem there : )

To solve this IE problem (yes…just so you know that’s an IE problem) a resize eventListener has to be declared in the set preloader method (see sample below). Then a modification in the centerPreloader has to be made.
Jesse placed :
x = (stageWidth / 2) - (clip.width / 2);
y = (stageHeight / 2) - (clip.height / 2);

instead use the following:
x = (stage.stageWidth / 2) - (clip.width / 2);
y = (stage.stageHeight / 2) - (clip.height / 2);

And there you go…now it works fine, even in IE : )

Sample - Source

Posted in Actionscript 3.0, Components, Did you know?, Flex |

5 Responses

  1. Maikel Sibbald Says:

    This is the good-shit.. Keep up the good work!!

  2. seth Says:

    score! I’ve been dealing with resolving this issue for too long. It included Firefox 3 and having been chasing a solution around. It seems like a bug in swfObject. thanks!

  3. Flex custom preloader does not center « Development scratchbook Says:

    […] the ’stage’ property (see blog jaap kooker). And unhide the preloader if we get a valid value for the stage […]

  4. Eugene Tjoa Says:

    Hi, I tried your solution but it worked only partly for me.

    I added some code so that it works, at least for me.

    The main idea is that the function that centers the preloader is called each time an progress event is caught.

    See also:http://tjoadesign.nl/blog/?p=83

  5. Jaap Kooiker Says:

    @Eugene This fixes the “page refresh loader in left upper corner” problem. Cool!

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.