<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Hacking width and height properties into Flex&#8217;s CSS model</title>
	<link>http://www.craftymind.com/2008/03/31/hacking-width-and-height-properties-into-flexs-css-model/</link>
	<description>Hacking away at UI development</description>
	<pubDate>Fri, 21 Nov 2008 17:28:31 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>By: Scott Schafer</title>
		<link>http://www.craftymind.com/2008/03/31/hacking-width-and-height-properties-into-flexs-css-model/#comment-5490</link>
		<dc:creator>Scott Schafer</dc:creator>
		<pubDate>Mon, 10 Nov 2008 17:48:37 +0000</pubDate>
		<guid>http://www.craftymind.com/2008/03/31/hacking-width-and-height-properties-into-flexs-css-model/#comment-5490</guid>
		<description>This is very cool and useful - thanks for posting it. However, it seems to have a limitation: if you want to specify the position or dimensions of a component through CSS, you have to put it in an extHBox. What I really wanted is to be able to specify dimensions for, say, a text label directly in that text label's CSS declaration.

So here's what I came up with. This is a Canvas that not only gets its position and dimension properties from its CSS declaration, but gives the same flexibility to its children.

package view.containers
{
	/* inspired by http://www.craftymind.com/2008/03/31/hacking-width-and-height-properties-into-flexs-css-model
		
		This is a canvas that allows for the properties width, height, etc (see the properties array) to be set
		through the component's CSS file.  
	*/
	
	import mx.containers.Canvas;
	import mx.core.IUIComponent;
	import mx.core.UIComponent;

	public class CanvasExt extends Canvas
	{
		private static const properties : Array = ["width", "height", "percentWidth", "percentHeight", "x", "y", "visible"];
	
		public function CanvasExt()
		{
			super();
		}

		override public function styleChanged(styleProp:String):void
		{
			super.styleChanged(styleProp);
			if(!styleProp &#124;&#124; styleProp == "styleName")
			{ 
				//if runtime css swap or direct change of stylename
				updateProperties(this);
				for ( var i : int = 0; i &#60; numChildren; i++ )
				{
					var child : UIComponent = UIComponent ( getChildAt ( i ) );
					updateProperties ( child );
				}				
			}
		}
		
		private function updateProperties(obj:UIComponent):void
		{
			for each (var item:String in properties)
			{
				var prop:Object = obj.getStyle(item);
				if(prop != null)
					obj[item] = prop;
			}
		}
	}
}</description>
		<content:encoded><![CDATA[<p>This is very cool and useful - thanks for posting it. However, it seems to have a limitation: if you want to specify the position or dimensions of a component through CSS, you have to put it in an extHBox. What I really wanted is to be able to specify dimensions for, say, a text label directly in that text label&#8217;s CSS declaration.</p>
<p>So here&#8217;s what I came up with. This is a Canvas that not only gets its position and dimension properties from its CSS declaration, but gives the same flexibility to its children.</p>
<p>package view.containers<br />
{<br />
	/* inspired by <a href="http://www.craftymind.com/2008/03/31/hacking-width-and-height-properties-into-flexs-css-model" rel="nofollow">http://www.craftymind.com/2008/03/31/hacking-width-and-height-properties-into-flexs-css-model</a></p>
<p>		This is a canvas that allows for the properties width, height, etc (see the properties array) to be set<br />
		through the component&#8217;s CSS file.<br />
	*/</p>
<p>	import mx.containers.Canvas;<br />
	import mx.core.IUIComponent;<br />
	import mx.core.UIComponent;</p>
<p>	public class CanvasExt extends Canvas<br />
	{<br />
		private static const properties : Array = [&#8221;width&#8221;, &#8220;height&#8221;, &#8220;percentWidth&#8221;, &#8220;percentHeight&#8221;, &#8220;x&#8221;, &#8220;y&#8221;, &#8220;visible&#8221;];</p>
<p>		public function CanvasExt()<br />
		{<br />
			super();<br />
		}</p>
<p>		override public function styleChanged(styleProp:String):void<br />
		{<br />
			super.styleChanged(styleProp);<br />
			if(!styleProp || styleProp == &#8220;styleName&#8221;)<br />
			{<br />
				//if runtime css swap or direct change of stylename<br />
				updateProperties(this);<br />
				for ( var i : int = 0; i &lt; numChildren; i++ )<br />
				{<br />
					var child : UIComponent = UIComponent ( getChildAt ( i ) );<br />
					updateProperties ( child );<br />
				}<br />
			}<br />
		}</p>
<p>		private function updateProperties(obj:UIComponent):void<br />
		{<br />
			for each (var item:String in properties)<br />
			{<br />
				var prop:Object = obj.getStyle(item);<br />
				if(prop != null)<br />
					obj[item] = prop;<br />
			}<br />
		}<br />
	}<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
