-
colorTransform update
I cant seem to update the color of some simple graphics, which has me pretty stumped now.
Code:
import flash.geom.ColorTransform;
import flash.display.*;
import flash.events.*;
public class objects extends Sprite {
public var bigSquare:Sprite = new Sprite();
public var smallSquare:Sprite = new Sprite();
public function objects():void {
bigSquare.graphics.beginFill(0x2c6ccc);
bigSquare.graphics.drawRect(20,50,200, 200);
smallSquare.graphics.beginFill(0x4cc5cc);
smallSquare.graphics.drawRect(300,170,100, 100);
addChild(smallSquare);
addChild(bigSquare);
}
public function changeColor(object, color:uint):void {
var colorTransform:ColorTransform = bigSquare.transform.colorTransform;
colorTransform.color = color;
bigSquare.transform.colorTransform = colorTransform;
trace(colorTransform.color);
bigSquare.x = 500;
}
}
when the changeColor function runs I get the trace output showing the selected color, however nothing happens to the graphics. I even added the line bigSquare.x = 500 to see if that had any effect but nothing. What am I missing?? thanks.
-
You need to create a new Colortransform instance, which you are not doing. here is the corrected script:
PHP Code:
public function changeColor (object:Object, color:uint):void
{
var colorTransform:ColorTransform = new ColorTransform();
colorTransform.color = color;
object.transform.colorTransform = colorTransform;
trace (colorTransform.color);
}