Tuesday, October 11, 2011

FXG Scale Grid

When working with FXG an important concept to understand is the Scale Grid. The scale grid determines how your FXG graphic scales. If your FXG element is used without an explicit width or height (e.g. <fxg:rounded_box/>) then the scale grid is not used. But if for example you define your FXG to have a width of 200 pixels and then in your MXML you use the FXG element and set its width to "100%" (e.g. <fxg:rounded_box width="100%"/>) or something other than 200 you'll see the graphic get scaled. The scale grid becomes important when you want to preserve aspect ratios (e.g. on rounded corners).

Here is the typical example used to illustrate the problem:

Here is the FXG source code (rounded_box_scale9.fxg) used to create this graphic. Notice the scaleGridLeft, scaleGridTop, scaleGridRight, and scaleGridBottom properties, these are what control the scaling.
<s:Graphic xmlns:s="http://ns.adobe.com/fxg/2008" version="2.0" 
	scaleGridTop="20" scaleGridLeft="20" scaleGridRight="130" scaleGridBottom="21">
	<s:Rect height="41" width="150" radiusX="20">
			<s:LinearGradient rotation="90">
				<s:GradientEntry color="#FFFFFF"/>
				<s:GradientEntry color="#C0C0C0"/>
				<s:GradientEntry color="#FFFFFF"/>
			<s:SolidColorStroke color="#AAAAAA" weight="2"/>

And here is the associated MXML (the rounded_box fxg doesn't have the scaleGrid properties):
<s:VGroup x="10" y="10" gap="10">
	<fxg:rounded_box width="100"/>
	<fxg:rounded_box width="200"/>
	<fxg:rounded_box_scale9 width="100"/>
	<fxg:rounded_box_scale9 width="200"/>

I found this website quite useful in illustrating some of the scale grid limitations: http://www.adobe.com/devnet/flex/articles/mobile-skinning-part1.html.

And here is Adobe's page on FXG:

But to summarize, here are the limitations I've found with scale grids:
  • Scale grid values must be inside the boundaries of the graphic and must not overlap
    (that is, left boundary < scaleGridLeft < scaleGridRight < right boundary).
  • Scale grids will not work if the graphic contains any Group elements.
  • Scale grids will not work if elements have alpha applied. Instead, apply alpha to the stroke and fill elements.
  • Scale grids will not work with filters (e.g. DropShadow, GlowFilter, etc). Instead add the filters inside the MXML.
I'm sure there are more restrictions, but these are what I've found so far.

1 comment:

Felcy said...

Thanks for sharing, I will bookmark and be back again

Flash Development