Wow… every so often you stumble upon something that you know will change the way you design forever. I was flicking through the ACP (Adobe Certified Professional) Exam Guide for Flash CS3 (as you do on a Sunday), and came across something I didn’t recognise - scale9Grid.
scale9Grid divides a display object into 9 regions, allowing different rules to be applied to it when the object is scaled.
How is this useful?? Well.. think about designing a simple content area with rounded corners. You want the content area scale vertically as the amount of text it holds increases. With any normal object with rounded corners, as you scale it’s height, the corners would scale and distort the more it is verticaly scaled. Enter scale9Grid. With one line of code, you can define the regions of the rounded rectangle to allow for distortion free scaling… Here’s an example:
myRoundedRectangle.scale9Grid = new Rectangle(10,10,300,600);
The above code adds a scale9Grid to a rounded rectangle object - meaning when it is scaled, the rounded corners will stay the same…. Brilliant!