Don’t Just Skin It. Style It!<br />James Polancowww.developmentarc.comFlash Camp Brasil2011<br />
Who am I?<br />James Polanco<br />Web Application ArchitectFlex, Flash, AIR, Ajax... Getting into Scala and Lift<br />Co-f...
What is this session about?<br />Styling a Flex application has many different approachesCSS, MXML properties, Programmati...
Style Support in Flex : Flex 3 (Halo)<br />CSS in Flex 3<br />Benefits<br />Setting look and feel based on style declarati...
Style Support in Flex : Flex 3 (Halo)<br />Programmatic Skins in Flex 3<br />Benefits<br />	Full Control over all aspects ...
Style Support in Flex : Flex 4 (Spark)<br />CSS in Flex 4<br />Benefits<br />	Setting look and feel based on style declara...
Style Support in Flex : Flex 4 (Spark)<br />New Skin Architecture in Flex 4<br />Benefits<br />Replaces Programmatic skin ...
Understanding Spark (Flex 4)<br />Brief look at the new Flex 4 (Spark) Architecture<br />Creates a separation of layout fr...
Understanding Spark (Flex 4)<br />Brief look at the new Flex 4 (Spark) Architecture<br />
CSS in Flex 4<br />CSS support still exists in Flex 4 (Spark) components<br />New properties have been created for general...
CSS in Flex: What are styles?<br />What are styles?<br />	Settings of a component that enable the ability to change the lo...
CSS in Flex: Setting Styles<br />Four ways we can set styles in Flex<br />ActionScript<br />setting styles directly in our...
CSS in Flex: Setting Styles, ActionScript<br />myButton.setStyle("color", 0xFF0000);<br />Styles are not properties of com...
CSS in Flex: Setting Styles, MXML<br /><s:Button id="myButton" color="#FF0000" /><br />Styles are exposed as properties in...
CSS in Flex: Setting Styles, <Style> Block<br /><fx:Style>.myStyle {		color: #FF0000;<br />	}<br /></fx:Style><br /><s:But...
CSS in Flex: External Stylesheets<br /><fx:Stylesrc=“/assets/css/myStylesheet.css” /><br /><s:Button id=“myButton” styleNa...
CSS in Flex: Selectors<br />What is a Selector?<br />Defines how a style is applied and in what context<br />There are fou...
CSS in Flex: Type Selectors<br />What is a Type Selector?<br />Defines global styles for any “type” of component that is c...
CSS in Flex: Class Selectors<br />What is a Class Selector?<br />Defines styles that must be explicitly referenced by the ...
CSS in Flex: ID Selectors<br />What is an ID Selector?<br />Components with the explicit ID apply these styles (new in Fle...
CSS in Flex: Pseudo Selectors<br />What is a Pseudo Selector?<br />	Pseudo selectors work in conjunction with other select...
CSS in Flex: Namespaces<br />What is a Namespace?<br />	Namespaces are new in Flex 4 and now required for any CSS declarat...
CSS in Flex: Chaining Selectors<br />We can now chain selectors<br />Chaining allows us to share properties across differe...
CSS in Flex: Dependent Selectors<br />We can define dependent selectors<br />With a dependent selectors we can apply style...
CSS in Flex: Linking Selectors<br />We can link type, class and id selectors to identify elements<br />By linking type, cl...
CSS in Flex: Cascading<br />Cascading is the C in CSS<br />CSS’ (Cascading Style Sheets) power is the ability to define st...
CSS in Flex: Cascading<br />Chain of Command<br />Understanding the priority order of what style overrides the cascading p...
Supporting CSS in Flex<br />How do we leverage it in our own components?<br />	We can support CSS in our custom components...
Supporting CSS in Flex: Methods<br />setStyle()<br />The setStyle() method allows us to define a style directly to our com...
Supporting CSS in Flex: Metadata<br />Metadata informs the compiler and tools (like Flash Builder) what styles are support...
Flex 4: Styling With Skins<br />Creating MXML Skins<br />	Flex 4 supports creating new looks for components using the skin...
Flex 4: CSS in Skins<br />Override updateDisplayList()<br />In the Skin class we can override the updateDisplayList() meth...
Flex 4: Skin States & CSS<br />States allow the skin to update the look of the UI<br />	Skin States defined in the host co...
CSS in Skins: Using FXG<br />FXG is Adobe’s new declarative graphics language<br />FXG allows us to create vector based as...
Wrapping it up...<br />Flex 4 is adding a lot of styling opportunity<br />Advanced CSS functionality and the new skinning ...
Thank you... Any Questions?<br />Any questions?<br />	Ask them if you got them...<br />James Polanco<br />	Twitter: @james...
Upcoming SlideShare
Loading in …5
×

Adobe Flex Don't Style It, Skin it!

14,409 views

Published on

With the introduction of Flex 4's Spark architecture, Flex component skinning has never been easier. With this new skinning approach, the art of CSS styling components appears to have been left in the shadows of Flex development. Many of the Flex 4 version of components no longer provide the same level of CSS support as their Halo equivalent. However, Flex 4 has not abandoned CSS styling and it has even been enhanced with the Flex 4 SDK to allow for new ways to provide styling for components. In this session, we will walk through the CSS features of Flex, what is new with Flex 4, and how we can take advantage of CSS to help provide robust styling support for our components and more specifically our skins. Let's rediscover Flex styling together!

Published in: Technology

Adobe Flex Don't Style It, Skin it!

  1. 1. Don’t Just Skin It. Style It!<br />James Polancowww.developmentarc.comFlash Camp Brasil2011<br />
  2. 2. Who am I?<br />James Polanco<br />Web Application ArchitectFlex, Flash, AIR, Ajax... Getting into Scala and Lift<br />Co-founder of DevelopmentArcconsulting and development firm focusing on web applications<br />Author for Adobe Press“Adobe Flash Platform Start to Finish: Working Collaboratively using Adobe Creative Suite 5”<br />Twitter & Website@jamespolancowww.developmentarc.com<br />
  3. 3. What is this session about?<br />Styling a Flex application has many different approachesCSS, MXML properties, Programmatic Skins, 3rd Party libraries (ex: Degrafa)<br />Flex 3 (Halo) vs. Flex 4 (Spark)<br /> Each Component set (Halo & Spark) has similar and different features to support styling of your Flex components. <br />Flex 4 (Spark) is changing how we work<br />Changes in the Flex 4 (Spark) component architecture is changing how applications are styled.<br />
  4. 4. Style Support in Flex : Flex 3 (Halo)<br />CSS in Flex 3<br />Benefits<br />Setting look and feel based on style declarations<br />An extensive set of styles are built into Flex 3 components<br />ex: Button has color, borderColor, backgroundColor, etc...<br />Limitations<br />Only able to change settings that are exposed to the CSS Style system <br />
  5. 5. Style Support in Flex : Flex 3 (Halo)<br />Programmatic Skins in Flex 3<br />Benefits<br /> Full Control over all aspects of the design<br /> Creating backgrounds that can show different component layouts, and add animations…<br />Limitations<br />Requires extensive ActionScript and understanding of the component architecture to implement<br /> Any design changes must be implemented via code (unless the code implements Flex’s style system)<br /> Programmatic skins are only defining the background of the component, you can not draw on top of content nor modify children without creating risky direct parent reference<br />
  6. 6. Style Support in Flex : Flex 4 (Spark)<br />CSS in Flex 4<br />Benefits<br /> Setting look and feel based on style declarations<br /> Improved CSS declaration support and advanced language features<br /> Style names are propagated from the component to the skin <br />Limitations<br /> Styles have less support in Flex 4 components<br /> ex: Button has color but does not support borderColor, backgroundColor, etc…<br />
  7. 7. Style Support in Flex : Flex 4 (Spark)<br />New Skin Architecture in Flex 4<br />Benefits<br />Replaces Programmatic skin with MXML based skinning system<br /> Rapidly create and change skins as need<br /> Separates logic from layout<br /> You can easily manipulate the components children parts and styles, unlike programmatic skins in Flex 3<br />Limitations<br /> Can require development for each layout / design<br /> CSS support within a skin requires extra development<br />
  8. 8. Understanding Spark (Flex 4)<br />Brief look at the new Flex 4 (Spark) Architecture<br />Creates a separation of layout from logic<br />A Spark component is made up of two parts: the Skin (look & feel) and the backing Component (logic)<br />Allows the look and feel of a component to be changed at runtime<br />Skins are assigned via CSS (skinClass) and can be changed at any time.<br />
  9. 9. Understanding Spark (Flex 4)<br />Brief look at the new Flex 4 (Spark) Architecture<br />
  10. 10. CSS in Flex 4<br />CSS support still exists in Flex 4 (Spark) components<br />New properties have been created for general themes, such as contentBackgroundColor<br />It’s not as supported as Flex 3 but...<br />Many of the previous Flex 3 CSS properties on the new Flex 4 versions of the components do not exist (yet...)<br />Flex 4 has more CSS features!<br />Many new advanced CSS features, such as ID and pseudo selectors (we will examine this in depth later)<br />
  11. 11. CSS in Flex: What are styles?<br />What are styles?<br /> Settings of a component that enable the ability to change the look and feel of a component dynamically<br />For example, setting the font color on a button<br /><s:Button color="#FF0000" /><br />
  12. 12. CSS in Flex: Setting Styles<br />Four ways we can set styles in Flex<br />ActionScript<br />setting styles directly in our code<br />MXML<br />setting properties on our MXML components<br /><Style> Blocks<br />defining a style block in our MXML file<br />External Style Sheets<br />linking to external CSS files to define our styles<br />
  13. 13. CSS in Flex: Setting Styles, ActionScript<br />myButton.setStyle("color", 0xFF0000);<br />Styles are not properties of components<br />This means we can’t do things like: <br />myButton.color = 0xFFFF00<br />Flex provides a Style Manager<br />The Style Manager handles complex style inheritance and other properties of CSS for us<br />To set a style we use the setStyle() method<br />Because styles aren’t properties and are handled by the Style Manager we use the setStyle() method, whose job is to work with the Style Manager to handle all the complex reltionships<br />
  14. 14. CSS in Flex: Setting Styles, MXML<br /><s:Button id="myButton" color="#FF0000" /><br />Styles are exposed as properties in MXML<br /> MXML treats styles as properties of our components<br />MXML hides the fact that styles are not properties on a component<br />MXML and the compiler handle converting our style “properties” into setStyle() commands at compile time<br />
  15. 15. CSS in Flex: Setting Styles, <Style> Block<br /><fx:Style>.myStyle { color: #FF0000;<br /> }<br /></fx:Style><br /><s:Button id=“myButton” styleName=“myStyle”/><br />A local style definition is created in the MXML and linked through CSS binding techniques<br /> We can create local style definitions and then apply them to our components (more to come...)<br />
  16. 16. CSS in Flex: External Stylesheets<br /><fx:Stylesrc=“/assets/css/myStylesheet.css” /><br /><s:Button id=“myButton” styleName=“myStyle”/><br />Externally referenced style definitions are linked into our MXML and are applied<br />Similar to our local style definition, we can link to external CSS files which are applied<br />
  17. 17. CSS in Flex: Selectors<br />What is a Selector?<br />Defines how a style is applied and in what context<br />There are four selector types in Flex<br />Type Selector<br />Class Selector<br />ID Selector<br />Pseudo Selector<br />
  18. 18. CSS in Flex: Type Selectors<br />What is a Type Selector?<br />Defines global styles for any “type” of component that is created, such as a Button, ComboBox, List, etc...<br />/* All Buttons in our application have their font color set to red: */<br /> Button { color: #FF0000;}<br />
  19. 19. CSS in Flex: Class Selectors<br />What is a Class Selector?<br />Defines styles that must be explicitly referenced by the component using the “styleName” property:<br />ex: <s:ButtonstyleName="myStyle" /><br /> /* Only components that reference this style has their font color set to red: */<br /> .myStyle { color: #FF0000;}<br />
  20. 20. CSS in Flex: ID Selectors<br />What is an ID Selector?<br />Components with the explicit ID apply these styles (new in Flex 4)<br /> ex: <s:Button id=“myButton” /><br />/* Only components that have id=“myButton” has their font color set to red: */<br /> #myButton { color: #FF0000;}<br />
  21. 21. CSS in Flex: Pseudo Selectors<br />What is a Pseudo Selector?<br /> Pseudo selectors work in conjunction with other selectors (Type, ID, Class)<br /> Allows us to changes style based on the current state the component is in (such as a button’s up, over, down & disabled states)<br /> The component must support the state to apply the style, stateGroups are not supported<br /> /* Change the color based on state: */<br />Button:up { color: #FF0000;}<br />Button:down { color: #00FF00;}<br />
  22. 22. CSS in Flex: Namespaces<br />What is a Namespace?<br /> Namespaces are new in Flex 4 and now required for any CSS declarations<br /> Allow us to support type selectors<br /> When we say “Button” do we mean Halo or Spark buttons?<br />@namespace s "library://ns.adobe.com/flex/spark";<br />@namespace mx "library://ns.adobe.com/flex/mx";<br />s|Button {<br /> color: #FF0000;<br />}<br />
  23. 23. CSS in Flex: Chaining Selectors<br />We can now chain selectors<br />Chaining allows us to share properties across different style types<br />s|Button, .blueText, #myLabel {<br /> color: #0000FF;<br />}<br />
  24. 24. CSS in Flex: Dependent Selectors<br />We can define dependent selectors<br />With a dependent selectors we can apply styles to elements based on their parents, the space between the selectors informs the CSS engine that the style should be applied based on the parent/child relationship<br />s|HGroups|Button {<br /> color: #0000FF;<br />}<br /><s:HGroup><br /> <s:Button id=“myButton” /><br /></s:HGroup><br />
  25. 25. CSS in Flex: Linking Selectors<br />We can link type, class and id selectors to identify elements<br />By linking type, class and id selectors together we can explicitly define what and when an element should have a style applied. The style is linked when there is NO space between the selectors<br />S|Button#myButton.labelText {<br /> color: #0000FF;<br />}<br /><s:Button id=“myButton” styleName=“labelText” /><br />
  26. 26. CSS in Flex: Cascading<br />Cascading is the C in CSS<br />CSS’ (Cascading Style Sheets) power is the ability to define styles and have them apply down the parent/child hierarchy automatically<br />How does it work?<br />Inheritable Styles: If the parent has a style set (such as color) and the child supports the style, then the child’s style is set to the parents value. Inheritance is defined via the [Style] metadata<br />Non-Inheriting Styles: If the parent has the style set and the child supports the style, the value is NOT passed on<br />Global Styles: Flex supports the global tag, which applies this style to EVERYTHING in the application<br />
  27. 27. CSS in Flex: Cascading<br />Chain of Command<br />Understanding the priority order of what style overrides the cascading parents value OR the style definition location is very important<br />Global > Type > Class > ID > local > setStyle()<br />setStyle() overrides a local definition, a local definition overrides an ID definition, an ID definition overrides a Class definition, a Class definition overrides a Type definition and a Type definition overrides a global definition.<br />
  28. 28. Supporting CSS in Flex<br />How do we leverage it in our own components?<br /> We can support CSS in our custom components by using a combination of Metadata, ActionScript and the new Flex 4 Skin architecture<br />ActionScript Methods<br />Flex provides multiple methods for creating, managing and accessing styles<br />Metadata<br />Metadata allows us to define what styles our components support, how they cascade, their type and their default values <br />Flex 4 Skins & FXG<br />Flex 4 changes where we manage our styles and also supports a new way to apply and visualize our UI with these style settings<br />
  29. 29. Supporting CSS in Flex: Methods<br />setStyle()<br />The setStyle() method allows us to define a style directly to our component. We pass in a style name and the style value:<br />setStyle("color", 0xFF0000);<br />getStyle()<br />The getStyle method allows us to determine what the current value for the style is:<br />varourColor:Number = getStyle("color");<br />styleChanged()<br /> The styleChanged() method is called on our component whenever a defined style is updated.<br />updateDisplayList()<br />The updateDisplayList() method is where we should do all our style calculations and application to our content.<br />
  30. 30. Supporting CSS in Flex: Metadata<br />Metadata informs the compiler and tools (like Flash Builder) what styles are supported<br />Metadata is how MXML can show a style as a property. Without metadata the compiler would not recognize the style property and throw an error at compile time.<br />Styles can still be used without metadata<br />We can still use the ActionScript methods, such as set and get style, even if the metadata isn’t defined.<br />Metadata is defined on the component (ActionScript) class and not a Skin (Flex 4+)<br />The metadata is assigned to the base component and not to a skin, for a component to fully support in MXML it has to be defined on the class:<br />[Style(name="errorColor", type="uint", format="Color", inherit="yes")]<br />
  31. 31. Flex 4: Styling With Skins<br />Creating MXML Skins<br /> Flex 4 supports creating new looks for components using the skinning architecture. Similar to Programmatic skins, but easier to create and you can use MXML to define them.<br />Setting Skins<br /> Skins are attached to a component using the skinClass style property, they can be defined in CSS using the ClassReference wrapper.<br />skinClass: ClassReference(”com.example.package.skin.SkinFile");<br />Swapping Skins<br /> Because skins are defined via styles we can change them at any time by either referencing a new style declaration or by using setStyle().<br />
  32. 32. Flex 4: CSS in Skins<br />Override updateDisplayList()<br />In the Skin class we can override the updateDisplayList() method and then use getStyle() to retrieve the property values defined for the style.<br />Update the skin with the style values<br /> Once the values have been pulled from getStyle() we can then apply the values to the parts of the skin that the styles correspond to.<br />Expose style via Metadata on the base component<br />To support style properties in MXML for our skins, the host component the skin is attached to should declare the styles using metadata.<br />
  33. 33. Flex 4: Skin States & CSS<br />States allow the skin to update the look of the UI<br /> Skin States defined in the host component allow our skins to change the look and feel based on user interaction. Think Button and the up, over, down, and disabled state.<br />Using CSS pseudo selectors enables us to change the style on state changes<br />When we define pseudo selectors ( .myStyle:up{} ) the getStyle() method will return the updated value in the updateDisplayList() method when our states change. This allows us to easily define and support CSS state changes in our skins.<br />
  34. 34. CSS in Skins: Using FXG<br />FXG is Adobe’s new declarative graphics language<br />FXG allows us to create vector based assets in MXML<br /><s:Rect top="0" left="0" right="0" bottom="0"> <s:fill><s:SolidColor id="bgColor" color="#CDCDCD"/></s:fill> </s:Rect><br />Modify FXG properties to enable CSS customizable skins<br />When the state changes we can reference and then update the FXG<br />bgColor.color = getStyle("backgroundColor");<br />
  35. 35. Wrapping it up...<br />Flex 4 is adding a lot of styling opportunity<br />Advanced CSS functionality and the new skinning architecture is allowing for easier customization of your application.<br />CSS is currently less prevalent in the current component set<br /> The current Spark components are at 100% parity yet, but more default CSS support is being added in Flex 4.5.<br />Create styles for your own application<br /> Using customer CSS in both your components and skins allows for rapid changes and flexibility to your applications look and feel.<br />
  36. 36. Thank you... Any Questions?<br />Any questions?<br /> Ask them if you got them...<br />James Polanco<br /> Twitter: @jamespolanco<br /> Email: info@developmentarc.com<br /> Website: http://www.developmentarc.com<br />

×