Yep @denisgladkiy, works fine with scale9grid... the only thing is that you will have to subclass Image to access vertexData.
If you plan to use it for different Mesh classes (like a GradientImage and MeshRoundRect), you could add an utility function to apply grad fills, lets say UIUtils.as
take John's code, remove var vData from initialization, and add vData as the first param.
UIUtils.as
public static function gradientFill(vData:VertexData, bearing:Number, col0:uint, col1:uint):void {
// ...
}
Then make your GradientImage class, (or name it as you want, if you only want to expose the ::vertexData protected member, or include John's method inside the instance, works as well..)
GradientImage.as
public class GradientImage extends Image {
public function GradientImage(texture:Texture = null) {
super(texture);
}
public function gradientFill(bearing:Number, c0:uint, c1:uint) {
UIUtils.gradientFill(vertexData, bearing, c0, c1);
}
}
}
And use it:
// lets say you have a round rect texture ("round rect radius 12") with corner radius 12, and texture size 30x30.
var texture:Texture = assetsMan.getTexture('round rect radius 12');
Image.bindScale9GridToTexture(texture, new Rectangle(12, 12, texture.width-12*2,texture.height-12*2));
var roundRect:GradientImage = new GradientImage(texture);
roundRect.width = 300;
roundRect.height = 140;
roundRect.x = 100 ;
roundRect.y = 100;
roundRect.gradientFill(Math.PI / 4, 0xff6e7f, 0xbfe9ff);
addChild(roundRect);