String to Hexadecimal Conversion

HI !

a quite simple problem in fact… …but can’t get rid of ! :blush:

I parse a file from which I fetch String variables representing Hexadecimal values, in order to use them as RGB color codes.

How to convert these Strings into Hexadecimal values ?

For example, I load a variable with the value “0xFFFFFF” from a file. This varaible is a String. I want to use the value in a SetRGB function, but it can not handle String, and can’t do the conversion itself. So, how can make such a conversion ?

my_color.setRGB(“0xRRGGBB”) does not work.
I need my_color.setRGB(0xRRGGBB).

Any idea ?
:A+:

parseInt()

hum…
well, a s far as I knew, parseInt returns an integer value, not an hexadecimal. And functions like SetRGB requires an numeric hexadecimal value, don’t they ?

tell me wheter I’m wrong but,

if I wrote parseInt(“0x0000FF”, 16), I’ll get 255. WHat I need to get is 0x0000FF, as a numeric hexadecimal value.

:puzzle: I’m confused

just tested this:
[AS]
myRGB = “0xffaaff”;
parsedRGB = parseInt(myRGB);
myColor = new Color(myMC);
myColor.setRGB(parsedRGB);
myMC.color
[/AS]

and it works as far as I can see.

setRGB() can take a decimal integer or a hexidecimal value.

well, it seems the setRGB functions can handle integer values…

I should have made this test before asking my stupid questions :frowning:
I was misguided by the flash documentation that always talk about hexadecimal values in its examples.

Anyway, thxx for your answer, cause parseInt does the job well, and now my work… works ! :slight_smile:

Flashmatazz , Rysolag : yep ! :slight_smile: I was writing my answer while you’were posting yours :wink:

Again, thxx for your quick support :slight_smile:

No problem.

And:

*Originally posted by jess *
**and now my work… works ! :slight_smile: **

LOL

hexidecimal IS an integer. Its just a different format of writing it. Instead of using units of 10 per decimal place, it uses 16, hense the extra 6 letters used to write it. Even so, the value represented is no different than numbers which can be written in base 10.

0x000000 == 0
0x0000FF == 255
0xFFFFFF == 16777215

Its all the same.

Also, I was too lazy to type it before, but setRGB does allow string arguments. my_color.setRGB(“0xRRGGBB”) should work fine.

yes, it does it fine.
Thanxx for the lesson, lazy Senseï :ninja: … :stuck_out_tongue: