BetaDesigns( Blog ) Flex and Component Development

18May/081

Static Code

I have recently seen some interesting posts regarding the topic of Static code blocks especially over at InsideRIA I posted my own two cents over there but I will also post it here for future reference:

I often use static variables for creating default styles for my components, these styles then can be overwritten by someone using the component however there will always be my initial stying applied if they arent overwritten.

/***** DEFAULT STYLE DECLARATIONS GO BELOW ***/
 
private static var STYLES : Boolean = defaultStyles( );
 
private static function defaultStyles( ) : Boolean
{
   //NO CSS DECLARATIONS
   var newStyle : CSSStyleDeclaration = new CSSStyleDeclaration( );
   if( !StyleManager.getStyleDeclaration( 'yOffSet' ) )
   {
      newStyle.setStyle( 'yOffSet', 30 );
   }
   StyleManager.setStyleDeclaration(
                                     'CustomComponentName',
                                      newStyle,
                                      true
                                    );
 
   return true;
}