November 2007

To the naysayers of MXML / “I don’t see that it’s any better if I can write it all out myself in AS” / progress antagonists, if you’re the type to write ItemRenderers and/or ItemEditors this is where you single-handedly loose in time & money, readability, code quality. Every time. (Those who I previously worked for should seriously pay attention -free lesson here -but they never paid attention to me the 1st time around =) . (more…)

Flex 2 Development Guide (PDF): Styles : Pg 742

This one I know gets missed.A LOT. The key here is if you want set styles dynamically where it’s dependent upon conditions or states, the key is not to use the creationComplete event instead use preinitialize. This becomes even more true if the styles you set are on components that are either at or near the root level of the application tree.

Now for the majority of the application that only needs to be styled at startup, the best approach is similar to the way most Web Designers / Web Developers take the approach of style sheets: external or otherwise. Now if you use external css like I do, and your intent is to allow others either recompile your source (developers, enhancers) or dynamically pull from a well-known style sheet (application users), be nice and not only organize it but add comments as well where needed.

A common mistake that impacts performance is overusing or unnecessarily using the setStyle() method. In general, you only need the setStyle() method when you want to change styles on existing objects. Do not use it when setting up styles for an object for the first time. Instead, set styles in an

block, through an external CSS style sheet, or as global styles. It is important to initialize your objects with the correct style information, if you do not expect these styles to change while your program executes (whether it is your application, a new view in a navigator container, or a dynamically created component). Some applications must call the setStyle() method during the application or object instantiation. If this is the case, call the setStyle() method early in the instantiation phase. Early in the instantiation phase means setting styles from the component or application’s preinitialize event, instead of the creationComplete or other event. By setting the styles as early as possible during initialization, you avoid unnecessary style notification and lookup. For more information about the component startup life cycle, see Chapter 6, “Improving Startup Performance,” in Building and Deploying Flex 2 Applications.