0
Explorer
,
/t5/animate-discussions/casting-string-to-uint/td-p/154362
Nov 26, 2008
Nov 26, 2008
Copy link to clipboard
Copied
Hello,
Does anyone know how to cast a string into a uint?
I have tried some along the lines of the following:
var myStr:String = "0x000000";
var myUint:uint;
myUint = uint(myStr);
But i keep getting an error stating that there is a mismatch in variable types or i get a value of '65280' when I trace myUint. I understand that uint is a positive integer but i need to accept a string for the colour value and need to convert it to a string for use.
Any suggestions and correct answers are welcome. I will post or indicate the working solution once this problem has been solved.
Thanks in advance to everyone,
Lee
Does anyone know how to cast a string into a uint?
I have tried some along the lines of the following:
var myStr:String = "0x000000";
var myUint:uint;
myUint = uint(myStr);
But i keep getting an error stating that there is a mismatch in variable types or i get a value of '65280' when I trace myUint. I understand that uint is a positive integer but i need to accept a string for the colour value and need to convert it to a string for use.
Any suggestions and correct answers are welcome. I will post or indicate the working solution once this problem has been solved.
Thanks in advance to everyone,
Lee
TOPICS
ActionScript
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
1 Correct answer
Explorer
,
Nov 26, 2008
Nov 26, 2008
The uint equivalent of the hex value 0x000000 is 0.
Try this:
var s1:String = "0xffeedd";
trace(s1); //outputs 0xffeedd
var u:uint = uint(s1);
trace(u); // outputs 16772829
var s2:String = u.toString(16);
trace(s2); // outputs ffeedd
var s3:String = "0x" + s2;
trace(s3); // outputs 0xffeedd
The u is the numerical equivalent of the first string.
The second string converts back to hex and the third sticks the "0x" back on. Basically it's all the same value using a different system for reco...
Try this:
var s1:String = "0xffeedd";
trace(s1); //outputs 0xffeedd
var u:uint = uint(s1);
trace(u); // outputs 16772829
var s2:String = u.toString(16);
trace(s2); // outputs ffeedd
var s3:String = "0x" + s2;
trace(s3); // outputs 0xffeedd
The u is the numerical equivalent of the first string.
The second string converts back to hex and the third sticks the "0x" back on. Basically it's all the same value using a different system for reco...
Explorer
,
/t5/animate-discussions/casting-string-to-uint/m-p/154363#M5273
Nov 26, 2008
Nov 26, 2008
Copy link to clipboard
Copied
var s:String = "0x123456";
var u:uint = uint(s);
trace(u); // outputs 1193046
Should work.
Are you sure there's nothing else in there that is causing the problem?
var u:uint = uint(s);
trace(u); // outputs 1193046
Should work.
Are you sure there's nothing else in there that is causing the problem?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
leewilson86
AUTHOR
Explorer
,
/t5/animate-discussions/casting-string-to-uint/m-p/154364#M5274
Nov 26, 2008
Nov 26, 2008
Copy link to clipboard
Copied
Hi,
thank you for your reply. i have followed your instructions and that works but the trace value is not what I want. I am wanting to convert a string with the value of 0x000000 to a uint with a value of 0x000000 not with an obscure value. Its basically to change a colour fill for a shape.
If you are able to expand on this, it would be very helpful. I have read through the uint class and tried several things but had no luck and I cant seem to find anything which gives what I would like on Google or other reputable ActionScript 3.0 websites.
Thanks
Lee
thank you for your reply. i have followed your instructions and that works but the trace value is not what I want. I am wanting to convert a string with the value of 0x000000 to a uint with a value of 0x000000 not with an obscure value. Its basically to change a colour fill for a shape.
If you are able to expand on this, it would be very helpful. I have read through the uint class and tried several things but had no luck and I cant seem to find anything which gives what I would like on Google or other reputable ActionScript 3.0 websites.
Thanks
Lee
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Explorer
,
/t5/animate-discussions/casting-string-to-uint/m-p/154365#M5275
Nov 26, 2008
Nov 26, 2008
Copy link to clipboard
Copied
The uint equivalent of the hex value 0x000000 is 0.
Try this:
var s1:String = "0xffeedd";
trace(s1); //outputs 0xffeedd
var u:uint = uint(s1);
trace(u); // outputs 16772829
var s2:String = u.toString(16);
trace(s2); // outputs ffeedd
var s3:String = "0x" + s2;
trace(s3); // outputs 0xffeedd
The u is the numerical equivalent of the first string.
The second string converts back to hex and the third sticks the "0x" back on. Basically it's all the same value using a different system for recording it.
Try this:
var s1:String = "0xffeedd";
trace(s1); //outputs 0xffeedd
var u:uint = uint(s1);
trace(u); // outputs 16772829
var s2:String = u.toString(16);
trace(s2); // outputs ffeedd
var s3:String = "0x" + s2;
trace(s3); // outputs 0xffeedd
The u is the numerical equivalent of the first string.
The second string converts back to hex and the third sticks the "0x" back on. Basically it's all the same value using a different system for recording it.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/animate-discussions/casting-string-to-uint/m-p/154366#M5276
Nov 26, 2008
Nov 26, 2008
Copy link to clipboard
Copied
There is nothing obscure about what the uint value of a
hexadecimal value is--you will not get a uint value to be a
hexadecimal value, just the integer value equal to the hexadecimal
vaue. Have you tried using the value it does produce for the
colorfill?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
New Here
,
/t5/animate-discussions/casting-string-to-uint/m-p/154367#M5277
Mar 23, 2009
Mar 23, 2009
Copy link to clipboard
Copied
I am having the same problem. The drawing API needs a uint.
Because people often pass #000000 instead of 0x000000 and casting a
string to a uint simply doesn't work for the drawing API, this
functionality is ambiguous.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

/t5/animate-discussions/casting-string-to-uint/m-p/154368#M5278
Mar 23, 2009
Mar 23, 2009
Copy link to clipboard
Copied
yeah ... but you can use string methods to check for
different rgb formats and convert. i.e.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

