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.

Convert values within a range to values within another range

Today I’m sharing with you a little utility that I find myself using a lot lately. This utility is a value convertor that you can use in those times when you need to make a volume slider or something similar where you’ll need to change a value and a value range.

```package com.vamapaull.utils { public class ValueConvertor { public static function convertRange(originalStart:Number, originalEnd:Number, newStart:Number, newEnd:Number, value:Number):Number { var originalRange:Number = originalEnd - originalStart; var newRange:Number = newEnd - newStart; var ratio:Number = newRange / originalRange; var newValue:Number = value * ratio; var finalValue:Number = newValue + newStart; return finalValue; } } }```
Odd or Even number in ActionScript

I was making a project for a client of mine where I had to make a list with two different colors for the items (like the iTunes list) so I started to think of a possible way to make this. It was clear enough I need to know the odd or the even number in order to do that. So I started to do some google search and I got over this blogpost by Keith Peters. I have to say, this is a very interesting way of thinking ðŸ˜€

iseven = ((num & 1) == 0)

Makes sense when you look at binary numbers:

001 = 1
010 = 2
011 = 3
100 = 4
101 = 5

Each of the odd numbers has a 1 in the far right column. The even numbers have 0 there. Mask it with â€œ& 1â€³ and you can see which it is.

So I made a for loop and used this code. It works exactly how it was intended to work!!
Thanks Keith Peters for your blogpost ðŸ˜€

Random number except number 7

Today I had this little problem. I needed to generate a random number from 1 to 30 and the result had to except a specific number (as in this example, any number from 1 to 30 except the number 7 )
The code is done now, it’s working as it should and I posted it in case someone else needs this same code.

```var randomNumber:Number; var minNumber:Number = 1; var maxNumber:Number = 30;   function generateRandomNumber():void{ randomNumber = Math.round(Math.random() * (maxNumber - minNumber)) + minNumber; if(randomNumber == 7){ generateRandomNumber(); } trace(randomNumber) } generateRandomNumber();```

By the way, the code here is ActionScript 3 but if you remove “:void” you can use it in ActionScript 2 too ðŸ˜‰