Hi to all,
i´ve got a problem with the scale9grid and can´t figure out why it dosen´t work for me.
class:
package {
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.LineScaleMode;
import flash.display.JointStyle;
import flash.events.Event;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import marek.Scale9Helper;
public class RoundedRectangle extends Sprite {
private var s:Shape = new Shape;
private var regX:Number = 0;
private var regY:Number = 0;
//
private var _sWidth:uint = 100;
private var _sHeight:uint = 100;
private var _sRadius:Number = 0;
private var _strokeS:Number = 0;
private var _strokeC:uint = 0xFF0000;
private var _fillInC:uint = 0xFFFFFF;
//
private var grid:Rectangle;
//
public function set cornerRadius(value:Number):void {
this._sRadius = value;
invalidate();
}
public function set strokeSize(value:Number):void {
this._strokeS = value;
invalidate();
}
private function invalidate():void {
this.addEventListener(Event.ENTER_FRAME, redraw);
}
private function redraw(e:Event = null):void {
s.removeEventListener(Event.ENTER_FRAME, redraw);
s.graphics.clear();
s.graphics.beginFill(_fillInC);
s.graphics.lineStyle(_strokeS,_strokeC,1,false,LineScaleMode.NORMAL,null,JointStyle.MITER);
s.graphics.drawRoundRect(0, 0, _sWidth, _sHeight, _sRadius, _sRadius);
s.graphics.endFill();
grid = new Rectangle( 20, 20, s.width - ( 20 << 1 ), s.height - ( 20 << 1 ) );
s.scale9Grid = grid;
// set registration point to the middle of the object
regX = (s.width >> 1) - (_strokeS >> 1);
regY = (s.height >> 1) - (_strokeS >> 1);
s.transform.matrix = new Matrix(1,0,0,1, -regX, -regY);
addChild(s);
}
}
}
with this class i draw a rect with rounded corner.
this class is used on the main class:
main class:
addChild(_pImg = new RoundedRectangle());
_pImg.x = 100;
_pImg.y = 100;
_pImg.cornerRadius = 45;
_pImg.strokeSize = 0;
code - scale function (i´ve shorten this):
....
var dist = Point.distance(new Point(mouseX,mouseY),_targCenter);
_target.scaleX = dist / _radius
...
i tried with and without stroke, but when i scale the mc it´s corner get´s streched - why?
maybe someone can give me an hint.
greets marek