PDA

View Full Version : Convert XML string to hexadecimal uint color


maguskrool
04-14-2008, 09:38 PM
Hello. I have an xml file containing color values to be applied in a series of shapes in my swf. However, when I try to assign the values, it doesn't work, it recognizes only a string and assigns the value 0 to the colors.

Can anyone help me with this? Thanks.


//my_color.xml
<color_list>
<color_1>0xFFBB00</color_1>
...
<color_n>0xAA33FF</color_n>
</color_list>

The xml is then parsed into a variable called xmlColor.

//.fla
var c1:uint = xmlColor.color_1;
trace (xmlColor.color_1) //0xFFBB00
trace (c1) //0

wvxvw
04-15-2008, 04:33 AM
parseInt('0xabcdef',16);

maguskrool
04-15-2008, 10:24 AM
Hi, thanks! I just noticed I was forgetting something in my code and thus not accessing the correct xml tag. The example I provided should work fine.

Sorry for wasting your time and again, thank you for your help.

adeem
05-05-2008, 12:30 PM
in case someone want to convert a string to uint color

like
var fontColor:String = "0xFFFFFF";
fontColor = fontColor.substring(1,fontColor.length);
var backgroundColor:uint = uint("0x"+fontColor)

shubs6
08-06-2008, 07:20 AM
Thanks adeem. it helped me too :-)

baquiano
01-18-2009, 05:51 PM
Thanks Adeem, your code helped a lot!

Re: maguskool, you can try the following:

var c1_str:String = xmlColor.color_1;
var c1:uint = uint("0x"+c1_str.slice(1,c1_str.length));

// or in one line

var c1:uint = uint("0x"+xmlColor.color_1.slice(1,c1_str.length));

aneuryzma
02-05-2009, 11:03 AM
It always give me 0. How is possible ?

var fontColor:String="0xCCCCCC";
fontColor=fontColor.substring(1,fontColor.length);
trace(uint("0x"+fontColor));

I need the parameters for this function
new ColorTransform(0,0,0,1,255,0,0,0);

wvxvw
02-05-2009, 11:45 AM
var fontColor:String = "#CCCCCC";
fontColor = fontColor.substring(1, fontColor.length);
trace(uint("0x" + fontColor));
You probably wanted to do this, otherwise why would you use substring()?