Here is the code I have:
private function drawRect():Sprite{
var rect:Sprite = new Sprite();
rect.name = "rectName";
rect.graphics.beginFill(0xffff00);
rect.graphics.lineStyle(1,0x000000);
rect.graphics.drawRect(0,0,6,6);
rect.graphics.endFill();
rect.addEventListener(MouseEvent.MOUSE_OVER, changeColor);
rect.addEventListener(MouseEvent.MOUSE_OUT, changeColorBack);
return rect;
}
private function changeColor(e:MouseEvent):void{
var newColor:ColorTransform = new ColorTransform();
newColor.color = 0x00ffff;
e.target.transform.colorTransform = newColor;
}
private function changeColorBack(e:MouseEvent):void{
var newColor:ColorTransform = new ColorTransform();
newColor.color = 0xffff00;
e.target.transform.colorTransform = newColor;
}
The changeColor and changeColorBack functions work but not how I would like them to. They change the whole color of my Sprite including the line border(stroke) around the rectangle. I want to change just the color inside the rectangle and maintain the rectangle's border. I don't see a property in the ColorTransform that allows me to specify the lineStyle so is there a different approach to changing the fill color of my rectagle and maintain the border around it?
ColorTransformapplies to the wholeMovieClipregardless of what's drawn in its graphics property. You could either redraw the rectangle each time you need to:Or, if you're set on using
ColorTransformfor some reason, you could build your outlined rectangle out of two separateSprites(an outer and an inner) and target the innerSpriteonly with theColorTransform: