Tracing or tracking a uint as a Hex String in AS3

I feel guilty that I haven’t written in a two weeks but I have been working on a longer article and it seems that I am limited on the number of words I can write in a week. Anyway I wanted to make a small post about this topic because I had a bit of trouble to find how to do it. When you work with colours, the common way to write a colour is to write it a has hex string to a uint; example: 0xff0000. When you trace that uint what you will get is the base 10 equivalent which is not really readable and gives no hint about what colour it is. So to solve this problem here is a quick way to convert a uint into a Hexadecimal String for tracing or tracking purpose:

 
var myUint:uint = 0xff000; // this is the colour red
 
trace (myUint.toString(16)); //will trace ff0000;

My guess is that it will trace the number using 16 as a base.

Well that’s it for now might have more on AIR later on.

, , , , ,

  1. #1 by Tyler Egeto - February 3rd, 2009 at 22:37

    Hey, thanks for sharing this, I had no idea you could to this. Definitely something that could have come in handy in the past.

  2. #2 by loover - September 9th, 2009 at 16:08

    great! how convert hex to uint&

  3. #3 by loover - September 9th, 2009 at 16:09

    sorry. how covvert uint to hex?

  4. #4 by ilu - October 21st, 2011 at 06:59

    How do convert from Number to Hexadecimal color code formai in as3?

  5. #5 by Jay - February 16th, 2012 at 14:46

    Post is old but is seems no solution was provided for the above questions…let me provide one :D
    To convert hex to uint, do this:

    1. var stringColor:String = ‘#FFFFFF’;
    2. stringColor = stringColor.substr(1,6); // result FFFFFF
    3. var colorUint:uint = parseInt(’0x’ + stringColor); result 16777215

  6. #6 by puggsoy - October 23rd, 2012 at 17:47

    Thanks man, this is really what I needed for checking colours in uint. Also thanks Jay, that’ll probably come in handy for the future.

  7. #7 by jeba - February 15th, 2013 at 01:34

    I had place a movie clip dynamically in a array, and transform color for this array elements having 25, now how can i give id and name for the movie clip…and how to access(ie. click) this movieclip

  8. #8 by jeba - February 15th, 2013 at 01:35

    I had place a movie clip dynamically in a array, and transform color for this array elements having 25, now how can i give id and name for the movie clip…and how to access(ie. click) this movieclip………… wish u plz send this answer to my mail jeba_91@ymail.com

(will not be published)
Subscribe to comments feed