JoJo
JoJo

Reputation: 20115

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 resizing of DOM elements. In JS, resizing a box would never alter its border.

Upvotes: 2

Views: 1389

Answers (4)

Arc676
Arc676

Reputation: 4465

For posterity, as OP has mentioned, this option can be modified directly in the IDE.

Scale dropdown in Flash

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.

Upvotes: 0

Chunky Chunk
Chunky Chunk

Reputation: 17217

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;

Upvotes: 6

citizen conn
citizen conn

Reputation: 15390

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.

Upvotes: 0

Jacob Eggers
Jacob Eggers

Reputation: 9322

With 9 Scale Slicing

Upvotes: 2

Related Questions