setStyle == Huge CPU drain

Sam Neff recently explored how setStyle notifies components of style changes, and the results are definitely worth noting (this may save you some major headaches, so listen up). It seems that every time you call setStyle, it calls notifyStyleChangeInChildren(), which iterates through EVERY movieclip in your movie, checking to see if it should notify it of the style change… ouch! Double-ouch even.

This was very useful information for me, as I’m presently working on a (top secret) project that has 100+ components instantiated at a time, and I was a little confounded as to why initializing the first interface was taking about 12 seconds. It all became very clear when I realized that I was setting about 40 different styles, which resulted in literally TENS of THOUSANDS of movieclip “style checks”. Moving the setStyle calls to the first frame solved the problem completely.

The moral of this story: always set all of your global style information before instantiating ANY movieclips, and then don’t change it – at least until Macromedia changes their EULA, and someone can legally distribute a fix for it (jab, jab). 😉

Grant Skinner

The "g" in gskinner. Also the "skinner".

@gskinner

3 Comments

  1. Faire chauffer son cpu avec style!

    Un grand merci à Grant Skinner qui vient de dévoiler ici la cause d’un problème que j’avais avec ma première et dernière grosse application MX04 / AS2! La découverte est en fait de Sam Neff. La méthode setStyle servant à…

  2. Someone knows if MM is taking part in changing the EULA, that things only makes damage to Flash and his extension.

    I hope MM don’t take the same ways as Microsoft…

  3. The right post at right time. This really solves a few problems for me. thanks

Leave a Reply

Your email address will not be published. Required fields are marked *