| By Tariq Ahmed | Article Rating: |
|
| June 12, 2007 11:15 AM EDT | Reads: |
62,503 |
One thing you may have noticed when I introduced the out-of-the-box themes - a bunch of them were CSS files. Which begs the question: Can you source them in using the <mx:Style> tag? Yup! As mentioned before, style definitions are the root of your theme.
Just something to remember, though, is that you can't use the <mx:Style> to source in a theme SWC file; and using the -theme compiler option gives you extended flexibility to control what theme files to use during the build and release phase of the project (particularly useful for large projects).
Flex gives you many deployment options here so use whatever's most convenient.
The Skinny on Skins
For those of you who use WinAmp or Firefox you may have played around with their skins and seen how the look can be drastically altered. Flex lets you do the exact same things and more.
There's actually two ways to skin. Graphical skinning uses images to define parts or all of a component, and programmatic skinning lets you use code to define the way a component looks and behaves.
Here we're going to look at the graphical way of using JPEGs, GIFs, and PNGs to define the look of a component. When skinning you take into consideration the states of a component or control; the common states that most controls exhibit are the mouse off, mouse over, and mouse down states. One of the most popular things in HTML to represent graphically is the button, and to add some pizzazz you could use some JavaScript to add a rollover effect that swapped out the default image to a mouse over state image.
It's very simple in Flex; you use CSS/Styles to specify what assets to use for your graphical skins. In the Button Class (mx.controls.Button) documentation you'll notice it supports many Style properties, but namely the following skin-related properties:
- disabledSkin
- downSkin (mouse down)
- overSkin (mouse over)
- upSkin (mouse not over)
- selectedDisabledSkin
- selectedDownSkin
- selectedUpSkin
- selectedOverSkin
If you want to take it a bit further you can also create images for the disabled state (i.e., <mx:Button enabled="false"/>), as well for the selected skins that are used to skin the background and the border of the button.
To test them quickly, use the inline approach:
<mx:Button label="My Skinned Button"
overSkin="@Embed('button_over.png')"
downSkin="@Embed('button_down.png')"
upSkin="@Embed('button_up.png')"/>
Compile and run your application and you should see a button that changes when you mouse over it and click down on it.
If your button is big enough to contain the text it will retain its original size, but if it wasn't Flex will automatically scale it to a big enough size. Add a fontSize="25" to your Button tag and see how Flex scales it:
The whole Embed business is a directive that tells Flex to import the image during compile time. You can abstract the name of the actual image files out of the Button into a script area of your MXML and embed the image elsewhere so that your Button doesn't need to know the exact filenames involved by doing:
<mx:Script>
<![CDATA[
[Embed(source="button_over.png")]
[Bindable]
public var buttonOver:Class;
[Embed(source="button_down.png")]
[Bindable]
public var buttonDown:Class;
[Embed(source="button_up.png")]
[Bindable]
public var buttonUp:Class;
]]>
</mx:Script>
<mx:Button label="My Skinned Button" overSkin="{buttonOver}" downSkin="{buttonDown}" upSkin="{buttonUp}"/>
Of course even better is just wrapping that all up into a Style:
<mx:Style>
.skinnedButton
{
overSkin: Embed(source="button_over.png");
downSkin: Embed(source="button_down.png");
upSkin: Embed(source="button_up.png");
}
</mx:Style>
<mx:Button label="Skin Class" styleName="skinnedButton"/>
Published June 12, 2007 Reads 62,503
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
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Windows 7 – Microsoft’s First Step to the Cloud
- Ulitzer Provides a Powerful Social Journalism Platform
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Open Source Mobile Cloud Sync and Push Email
- Kindle 2 vs Nook
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- US Post Office Hops a Ride on NetSuite’s Cloud
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Building a Drag-and-Drop Shopping Cart with AJAX
- What Is AJAX?
- Google Maps! AJAX-Style Web Development Using ASP.NET
- Flashback to January 2006: Exclusive SYS-CON.TV Interviews on "OpenAjax Alliance" Announcement
- AJAXWorld Conference & Expo to Take Place October 2-4, 2006, at the Santa Clara Convention Center, California
- AJAX Sponsor Webcasts Are Now Available at AJAXWorld Website
- How and Why AJAX, Not Java, Became the Favored Technology for Rich Internet Applications
- "Real-World AJAX" One-Day Seminar Arrives in Silicon Valley
- AJAXWorld University Announces AJAX Developer Bootcamp
- AJAX Support In JadeLiquid WebRenderer v3.1
- Where Are RIA Technologies Headed in 2008?
- Struts Validations Framework Using AJAX






































