Skip to main content
December 15, 2009
Answered

How do I convert hex number to rgb?

  • December 15, 2009
  • 1 reply
  • 1681 views

My user is using a colourpicker to select the colour.  I then want to use that picked colour to change an objects colour via colour transform.  But colourTransform wants an RGB version of the colour.

This topic has been closed for replies.
Correct answer

Well I have tried it without the 0x but I'm still getting the error.  This is my code

var cardDetails:Array = new Array();                cardDetails['catColour']=petColour.selectedColor;

var catColour:ColorTransform = new ColorTransform()

               catColour=cardDetails['catColour'];

               viewCardScreen.catBody_mc.transform.colorTransform=catColour

Error is TypeError: Error #1034: Type Coercion failed: cannot convert 0 to flash.geom.ColorTransform. - so somehow my value isn't the right type for the colourTransform which is why I thought ti needed to be in RGB format.


Your value might be right, but your code isn't.

catColour=cardDetails['catColour'];

catColour is a colorTransform object... you probably want catColour.color =

1 reply

kglad
Community Expert
Community Expert
December 15, 2009

flash uses hexadecimal numbers for its rgb arguments.  just prefix the number with "0x" so flash recognizes the number as hexadecimal.

Inspiring
December 15, 2009

What do you mean "wants an RGB version"? That is a number So if you have a number you are good to go.

Just because colors are generally written in hex they are still just ints (or are they uints?). 0xff is 255. And generally you can use either form. It is just easier to visualize when it is done as a triplet.

So the following code:

var ct:ColorTransform=myClip.transform.colorTransform
ct.color=16711680;
myClip.transform.colorTransform=ct

works the same as if the color had been given as 0xff0000. Is that what you are asking or is there something more?

December 15, 2009

>>var ct:ColorTransform=myClip.transform.colorTransform

He meant to say:

var ct:ColorTransform = new ColorTransform();