Color transformation and resizing from center

I’m working on health bars for a small game i’m working on and I have run into two small problems.

The first is the sizing of the healthbar itself, doing something like this

healthbar.width = (currentHealth / maxHealth) * maxSize

Will move the bar, but I want it to scale from the center. If I understand correctly, resizing scales from the registration point but how I would change the registration point of a dynamic shape?

The second thing is the re-coloring of the bar as you lose health. Right now I’m using

hbar.transform.colorTransform = new ColorTransform(1, 1, 1, 1, ((maxHealth - currentHealth) / maxHealth ) * 255, (currentHealth / maxHealth) * 255, 0, 0);

Which works OK but I want it to work something like this:

at full health (100%) there should be 255 green, 0 red and 0 blue
at half health (50%) there should be 255 green, 255 red and 0 blue
at 0 health there should be 0 green, 255 red and 0 blue

Here’s a chart for the visual people.


l         <0----------50----------100>
RED      255         255            0
GREEN    0           255          255