Be a Supporter!

ColorTransform

  • 157 Views
  • 3 Replies
New Topic Respond to this Topic
danBuonocore
danBuonocore
  • Member since: Aug. 24, 2011
  • Offline.
Forum Stats
Member
Level 03
Game Developer
ColorTransform 2013-12-07 14:19:22 Reply

Is there a way to change a MovieClip's color without creating a new ColorTransform object? Something along the lines of

transform.colorTransform.redOffset = 100;

instead of

var ct:ColorTransform = new ColorTransform();
ct.redOffset = 100;
transform.colorTransform = ct;

Thanks!

MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to ColorTransform 2013-12-07 14:33:32 Reply

At 12/7/13 02:19 PM, danBuonocore wrote: Is there a way to change a MovieClip's color without creating a new ColorTransform object?
ct = transform.colorTransform;
ct.redOffset = 100;
transform.colorTransform = ct;

transform.colorTransform creates a new colortransform object anyway, so you don't have to make another new one.

Sam
Sam
  • Member since: Oct. 1, 2005
  • Offline.
Forum Stats
Moderator
Level 19
Programmer
Response to ColorTransform 2013-12-07 14:44:22 Reply

Additionally you could just compact it into a single line by using the ColorTransform constructor, if you want:

transform.colorTransform = new ColorTransform(1, 1, 1, 1, 255, 255, 255, 255);
kkots
kkots
  • Member since: Apr. 16, 2013
  • Offline.
Forum Stats
Supporter
Level 10
Blank Slate
Response to ColorTransform 2013-12-07 16:16:01 Reply

At 12/7/13 02:19 PM, danBuonocore wrote: Is there a way to change a MovieClip's color without creating a new ColorTransform object? Something along the lines of

transform.colorTransform.redOffset = 100;

YES

setRedColor(mc,100);
function setRedColor(mc:DisplayObject, clr:uint, temp_obj:ColorTransform=null):void{
  mc.transform.colorTransform=(temp_obj=mc.transform.colorTransform)==(temp_obj.redOffset=clr)?temp_obj;
}

Haha. Not really. Follow Sam's advice.


BBS Signature