How to scale the fill, but not the stroke in Actionscript?
Let's say I have a box. The fill is a gradient and the stroke has 1 pixel thickess. How would I resize its fill but keep the stroke thickness intact?
private function resizeMovieClip(newWidth:Number, newHeight:Number):void
{
this.movieClip.width = newWidth;
this.movieClip.height = newHeight;
}
Basically, I'd like to emulate Javascript's resiz开发者_如何学JAVAing of DOM elements. In JS, resizing a box would never alter its border.
set the scaleMode of the lineStyle() to LineScaleMode.NONE
var sh:Shape = new Shape();
sh.graphics.lineStyle(1.0, 0x000000, 1.0, false, LineScaleMode.NONE);
sh.graphics.beginFill(0xFF0000, 1.0);
sh.graphics.drawRect(0, 0, 100, 100);
sh.graphics.endFill();
addChild(sh);
sh.scaleX = sh.scaleY = 4.0;
With 9 Scale Slicing
Not sure how your MC is drawn but I would redraw the stroke every time it was resized:
private function resizeMovieClip(newWidth:Number, newHeight:Number):void
{
this.graphics.clear();
this.movieClip.width = newWidth;
this.movieClip.height = newHeight;
this.graphics.lineStyle(1,0x000000);
this.graphics.lineTo(this.width,0);
this.graphics.lineTo(this.width,this.height);
this.graphics.lineTo(0,this.height);
this.graphics.lineTo(0,0);
}
Disclaimer: Of course this will clear anything else drawn with the graphics API on it before re-drawing the border, and it might not work depending on how your MC is drawn.
For posterity, as OP has mentioned, this option can be modified directly in the IDE.
You will notice that the scaling has changed because the line might become thinner. If this does not happen, click on something else and then back on the line you are modifying. The scaling might have changed back to Normal. It appears that sometimes, changing the scaling doesn't work. If you make the scaling Horizontal or Vertical first, then change it to None, it should work.
精彩评论