May 18, 2008

Static Code

Filed under: Flex — Anthony @ 2:37 pm

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;
}

1 Comment »

  1. http://www.tink.ws/blog/styleutilgetdefaultstylename/

    might be of interest

    Comment by Tink — June 6, 2008 @ 2:34 pm

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .