<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Random Fractals&#187; stylesheets</title>
	<atom:link href="http://randomfractals.com/blog/flex/stylesheets/feed/" rel="self" type="application/rss+xml" />
	<link>http://randomfractals.com/blog</link>
	<description></description>
	<lastBuildDate>Sat, 27 Mar 2010 13:57:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Add Multiple UI Skins to your Flex application with Compiled CSS Stylesheets</title>
		<link>http://randomfractals.com/blog/2009/01/12/how-to-add-multiple-ui-skins-to-your-flex-application-with-compiled-css-stylesheets/</link>
		<comments>http://randomfractals.com/blog/2009/01/12/how-to-add-multiple-ui-skins-to-your-flex-application-with-compiled-css-stylesheets/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 21:42:11 +0000</pubDate>
		<dc:creator>Taras</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[compiled css]]></category>
		<category><![CDATA[flex ui skin]]></category>
		<category><![CDATA[stylesheets]]></category>

		<guid isPermaLink="false">http://tarasnovak.com/blog/?p=444</guid>
		<description><![CDATA[This short tutorial describes how to implement and load multiple UI skins in a Flex application, leveraging compiled CSS stylesheets.
1. Move all mxml component style settings that control visual aspects of the view controls  to a standalone stylesheet (defaultStyles.css in this example).
For a good separation of UI design and easy maintenance, typical UI control properties [...]]]></description>
			<content:encoded><![CDATA[<p>This short tutorial describes how to implement and load multiple UI skins in a Flex application, leveraging compiled CSS stylesheets.</p>
<p><strong>1. Move all mxml component style settings that control visual aspects of the view controls  to a standalone stylesheet (defaultStyles.css in this example).</strong></p>
<p>For a good separation of UI design and easy maintenance, typical UI control properties that should be moved to a stylesheet rather than specified inline include font and border settings, fill and background colors, padding, alignment, etc.</p>
<p>Use the CSS type selector to override the style settings for all the control instances and class selector with a styleName attribute to control individual control instance settings. Here is an example from the Flex 3 lang. ref. docs:</p>
<blockquote><p>A CSS rule such as</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">Button <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FF0000</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>affects every instance of the Button class; a selector like  <code>Button</code> is called a type selector.</p>
<p>A CSS rule such as</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.redButton</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FF0000</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>affects only components whose <code>styleName</code> property is set to<br />
<code>".redButton"</code>; a selector like <code>.redButton</code> is called a<br />
class selector and must start with a dot.</pre>
</blockquote>
<p><strong>2.Include default stylesheet in the main application mxml file:</strong><br />
</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Style</span> source=<span style="color: #ff0000;">&quot;assets/skins/defaultStyles.css&quot;</span> <span style="color: #7400FF;">/&gt;</span></span></pre></div></div>

<p><strong>3. Create alternative stylesheets for your CSS skins.</strong></p>
<p>Once the style settings you'd like to change are moved to a separate css file and you are happy with how your application looks with the default stylesheet, you can create alternative stylesheets to implement different UI skins.</p>
<p><span id="more-444"></span>Create new stylesheet for an alternative look and feel by saving the defaultStylesheet.css with a different filename. We'll create red.css for this example.</p>
<p>Don't forget to override style settings in your alternative UI skin css file to create a different appearance for your application.</p>
<p><strong>4. Compile all CSS stylesheets to SWF</strong></p>
<p>In Flex Builder, right-click on each stylesheet you'd like to load as an alternative UI skin at run-time and check Compile your CSS stylesheet to SWF option:<br />
<img class="alignnone size-full wp-image-449" title="compileskin1" src="http://tarasnovak.com/blog/wp-content/uploads/2009/01/compileskin1.png" alt="compileskin1" width="431" height="460" /></p>
<p><strong>5. Add ActionScript code to change CSS stylesheet at runtime:</strong></p>
<p>This code can be added to your main application mxml file or better yet a custom application control bar component.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">import</span> mx.styles.StyleManager;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _skin<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
&nbsp;
<span style="color: #3f5fbf;">/**
* Changes the selected skin by unloading current style declarations
* and loading new style declarations from the embedded stylesheet swf file.
*/</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> changeSkin<span style="color: #000000;">&#40;</span>skinUrl<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_skin <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    StyleManager.unloadStyleDeclarations<span style="color: #000000;">&#40;</span>_skin, <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #000000;">&#125;</span>
  _skin = skinUrl;
  StyleManager.loadStyleDeclarations<span style="color: #000000;">&#40;</span>_skin, <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// force immediate update</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><strong>6. Add UI control to your application control bar to enable CSS skin selection:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;">  <span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Skin Selection --&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;Skin:&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:ComboBox</span> id=<span style="color: #ff0000;">&quot;skinSelector&quot;</span></span>
<span style="color: #000000;">    change=<span style="color: #ff0000;">&quot;{changeSkin(skinSelector.selectedItem.data);}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:ArrayCollection</span><span style="color: #7400FF;">&gt;</span></span>
      <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> label=<span style="color: #ff0000;">&quot;Dark&quot;</span> data=<span style="color: #ff0000;">&quot;assets/skins/defaultStyles.swf&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
      <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> label=<span style="color: #ff0000;">&quot;Red&quot;</span> data=<span style="color: #ff0000;">&quot;assets/skins/red.swf&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:ArrayCollection</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:ComboBox</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>You can use combo box, as in this example, or change it to a menu option.</p>
<p>The skinSelector combo box has a list of the sample CSS UI skins we've created with data attributes specifying the full path to the stylesheet swf file.</p>
<p>The change event handler calls our changeSkin method to load the selected UI skin by unloading current style declarations and loading new style declarations from the compiled CSS stylesheet at runtime.</p>
<p><strong>Example</strong></p>
<p>You can view an example of how this works in my new <a href="http://www.tarasnovak.com/lab/Random3DView/Random3DView.html" target="_blank">Random3DView</a> sample application I've built to explore Away3D camera options and experiment with OpenFlux Plexiglass layouts.</p>
<p><a href="http://www.tarasnovak.com/lab/Random3DView/srcview/index.html" target="_blank">View Random3DView source code</a> to see this setup along with some other options I've created for 3D visualization testing purposes.</p>
<p>For a good overview of other Flex application skinning options, see <a href="http://scalenine.com/blog/2007/02/17/10-ways-to-skin-an-app/" target="_blank">10 Ways to Skin an App</a> on <a href="http://www.scalenine.com/" target="_blank">scalenine.com</a>.</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li>No Related Post</li></ul>]]></content:encoded>
			<wfw:commentRss>http://randomfractals.com/blog/2009/01/12/how-to-add-multiple-ui-skins-to-your-flex-application-with-compiled-css-stylesheets/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

