[SOLVED] Getting colour from text/number

Sunflower

  • Posts: 591
Hello!
Is there any way to convert text or number to colour? (best in Design Mode)
I haven't found such function, and I would like to have a way to do something like that (for example, converting "654321" to such colour). I mean, having over 16 millions attributes isn't exactly the best thing. ^^'

« Last Edit: July 21, 2011, 09:38:21 am by Sunflower »

Alexin

  • *
  • Posts: 3132
Color attributes are actually numbers. The AS3 type is uint, which is a 4 bytes unsigned integer.

You can set a color using a number, be it decimal or hexadecimal (Flash's favorite style). Hexadecimal is great because each pair of symbols represents a color channel. For example, the hex number FF00FF00 translates to a pure green color, fully opaque.

Decimal isn't so great because it's hard to visualize which color corresponds to a number.
"Find the fun"
alexin@stencyl.com

dineyin

  • Posts: 110
You could create an Attribute of type color, and then use the codeblock:



Make sure that you type in the attribute name as it shows up if you go into "Preview Code". There's also a useful function to convert an RGB color into a Stencyl color:


Sunflower

  • Posts: 591
Alright, it seems that I won't get away without coding (oh, how terrible, isn't it? :P ), but thanks, anyway. With that it shouldn't be hard to write a function coverting string such as "008080" to teal colour. ;)

Alexin

  • *
  • Posts: 3132
I suppose AS3 is smart enough to convert "008080" into a number.

_SomeColor = Number("008080");
"Find the fun"
alexin@stencyl.com