| By Tariq Ahmed | Article Rating: |
|
| June 12, 2007 11:15 AM EDT | Reads: |
62,659 |
To this:
Get Your Style On
Let's take things a bit farther and talk about the essence of styles. For all intensive purposes, styles are your theme and give you a vast amount of control.
At the basic level there are three ways of defining your styles and the style properties.
The first is called the Inline Style, and this is the same as in HTML where you style on-the-fly as needed. For example in HTML, you could use an Inline Style to customize some text:
<span style="font-size:18px;font-family:Tahoma">Hello Style!</span>
Similarly in Flex, you can use Inline Styles that are implemented as properties on the component or control that you're using. For example:
<mx:Text text="Hello Style!" fontFamily="Tahoma" fontSize="18"/>
The second and more flexible approach is to use a local style definition. This would be similar to using the <style> tag in HTML somewhere in your Web page.
As in HTML, there are two types of these definitions. The Type Selector style is one that applies to all instances of that definition, and the Class Selector style let's you apply it to specific components.
In HTML you could do this:
<style>
input
{
font-family:Tahoma;
font-size:14px;
color:#FF9900;
}
.myStyle
{
font-family:Verdana;
font-size:18px;
color:#CC0000;
}
</style>
<input value="use type definition">
<input value="use class definition" class="myStyle">
Which results in:
With Flex you can do the same thing using the <mx:Style> tag as follows:
<mx:Style>
TextInput
{
font-family:Tahoma;
font-size: 14px;
color:#FF9900;
}
.myStyle
{
font-family:Verdana;
font-size:18px;
color:#CC0000;
}
</mx:Style>
<mx:TextInput text="use type definition"/>
<mx:TextInput text="use class definition" styleName="myStyle"/>
Which produces nearly the exact same thing:
Although you can find all the CSS properties for all the components in the Flex documentation, the easiest way to experiment with styles in Flex is to use the Flex Style Explorer ( See figure 1). You'll find the link to this in the Flex Start page (select Help->Flex Start Page), and it provides an interactive tool to generating the style definitions that you can cut and paste into your Flex application.
Lastly, and ultimately the most modular approach would be to store your style definitions in a separate file known of course as the external style sheet. Once again Adobe makes this aspect easy to take advantage of by making it similar to what you already know from the land of HTML.
So pretty straightforward stuff; copy your Type and Class definitions into a .css text file then in your MXML file put the following in the file in use:
<mx:Style source="/path/to/your/stylesheet.css"/>
Published June 12, 2007 Reads 62,659
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Tariq Ahmed
Tariq Ahmed is the manager of product development at Amcom Computer Services, a former project lead at eBay, and host of www.cflex.net. He specializes in leveraging technology with process engineering to reduce operating costs while maximizing revenue potential. You can find him on the Web at www.dopejam.com.
![]() |
WebDDJ Duty Online Editor 08/14/06 06:07:57 AM EDT | |||
Please go right ahead, Dreamer. Perhaps you would post the URL back to this thread too - thanks!! Web Developer's & Designer's Journal |
||||
![]() |
Dreamer 08/14/06 04:07:57 AM EDT | |||
wonderful post. |
||||
![]() |
SYS-CON India News Desk 08/10/06 01:06:15 PM EDT | |||
One of the great things about Flex is that you get to spend most of your time working on the business logic and workflow, and less on the cosmetic aspect. This is because the Flex default's look-and-feel is great! The only problem of course is that most people won't spend much time customizing the look, resulting in many Flex apps looking the same. In Flex 1.5 many folks customized the color scheme, but few ventured into modifying the actual skins of the components. |
||||
![]() |
SYS-CON Italy News Desk 08/09/06 07:37:26 PM EDT | |||
One of the great things about Flex is that you get to spend most of your time working on the business logic and workflow, and less on the cosmetic aspect. This is because the Flex default's look-and-feel is great! The only problem of course is that most people won't spend much time customizing the look, resulting in many Flex apps looking the same. In Flex 1.5 many folks customized the color scheme, but few ventured into modifying the actual skins of the components. |
||||
![]() |
Web Developer's & Designer's Journal 08/09/06 04:14:54 PM EDT | |||
One of the great things about Flex is that you get to spend most of your time working on the business logic and workflow, and less on the cosmetic aspect. This is because the Flex default's look-and-feel is great! The only problem of course is that most people won't spend much time customizing the look, resulting in many Flex apps looking the same. In Flex 1.5 many folks customized the color scheme, but few ventured into modifying the actual skins of the components. |
||||
![]() |
Web Developer's & Designer's Journal 08/09/06 02:40:45 PM EDT | |||
One of the great things about Flex is that you get to spend most of your time working on the business logic and workflow, and less on the cosmetic aspect. This is because the Flex default's look-and-feel is great! The only problem of course is that most people won't spend much time customizing the look, resulting in many Flex apps looking the same. In Flex 1.5 many folks customized the color scheme, but few ventured into modifying the actual skins of the components. |
||||
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?









































