Flash 4 Styling: Know your Namespaces

18. June 2009 20:41

One difference between Flex 3 and Flex 4 is the extensive usage of namespaces.  Anyone who has used Flex 3 is familiar with namespaces on the most cursory level in the application tag as xmlns:mx="http://www.adobe.com/2006/mxml."  Creating custom components resulted in new namespaces such as xmlns:components="com.shawnyale.view.components", etc.  Namespaces help avoid collisions among components when they share the same name.  So if there were a button in my components dir, prefixing MY button with components:Button would help the compiler to locate the correct component and not use the standard mx:Button component.

In Flex 4, namespaces are also used in CSS stylesheets.  There is a difference in the style declaration in that the namespace(separated by spaces) is declared immediately in the css file and then any styles are declared using the | character (called a 'pipe' and is usually the shift backslash character).  So an example of the new style declaration is as follows:


@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/halo";

s|Button{

      color:#FF0000;

 

}

 

Minor change, but important to know nonetheless.  I've noticed that Flash Builder 4 no longer has a design view for your stylesheets.  Not really thrilled about this change, but it is what it is. 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments


Log in