Color Value To Hexadecimal

A simple utility class that will help you convert a color value (from numbers) to hexadecimal color value.

Basically you can convert the color value to hex string with colorNumber.toString(16);
Now, if you have this shade of blue “13311”, for example, it will be converted to “33ff”.

You can fix that with while(hexColor.length < 6) and add “0” to in front of the hex color output.

Read more
Quick Tip: Replace Breakline (\n) with comma

Today I have a very quick tip but useful. I’ve wasted a few minutes of my life trying to find an answer for this because I’m not an expert when it comes to regular expressions.

This code comes in handy if you’re trying to remove \n (a break line) from a string and you want to replace it with something else (line a comma, as shown in the example below) you can use the following code:

string.replace(/[\r\n]+/g, ",");
Quick Tip: Test to see if an XML attribute is present

Today I received a question about how to check and see if an attribute is present into a XML node.

I thought it wold be a good idea if I post the answer here in case someone else needs to do the same.

This is the ActionScript code:

if(node.@attributeName in node)
{
    //the attribute is here
}

As you can see, the code is very simple, “node” is your actual XML node and “attributeName” is exactly what it says, the name of your attribute inside the XML node (the one that you are checking to see if it is there).

Using lineStyle to draw stroke without affecting the size of the holder container

Have you ever tried to use the graphics class to draw a rectangle with a lineStyle (stroke) and then set bigger width and height values for the container that holds the graphic? If so, you probably noticed that there is a size difference between a rectangle with lineStyle and a rectangle without lineStyle.

If you trace the width and height values of the container, everything seems to be fine. Only if you run and look at the SWF you’ll notice a visual difference between those two (top image).

Read more