canoebrain
canoebrain

Reputation: 635

Flash color transform

I'm having difficulty with transforming colour in Flash. It should be easy I think, but for some reason my code isn't working as expected.

I have a bitmap graphic consisting of a colour spectrum from red to yellow to green (you know, like you see in an audio level meter).

I simply want to sample a colour from that bitmap and then tint a movie clip on stage that sampled colour. (the effect I'll be going for is coloured progress - the closer you get to 100% green is displayed, the closer you are to 0% it's red - I haven't implemented that part yet, but I'm not worried about that).

Anyhow, I sample the colour just fine, and tint my clip, but no matter what I tint the clip it comes up a different colour than what I've sampled (the trace is a different colour than what I see on the clip). I can't see where I'm going wrong - I'm hoping it's a stupid mistake and someone can spot it easily.

import flash.display.BitmapData;

var bmd:BitmapData = new BitmapData(mc_colourbar.width, mc_colourbar.height);

bmd.draw(mc_colourbar);

var pixelvalue:uint = bmd.getPixel(0, 1);

trace(pixelvalue.toString(16));

var colourtransform:ColorTransform = mc_box.transform.colorTransform;

colourtransform.color = uint("0xff" + pixelvalue);

mc_box.transform.colorTransform = colourtransform ;

mc_box is the clip on stage I'm trying to tint - it's simply a white square.

Any help is appreciated, thanks in advance!

Upvotes: 0

Views: 255

Answers (1)

Marcela
Marcela

Reputation: 3728

ColorTransform.color expects an RGB value, and it appears as though you're attempting to give it an ARGB value*.

Change the line:

colourtransform.color = uint("0xff" + pixelvalue);

to just:

colourtransform.color = pixelvalue;

and your code should work as expected.

*Though I don't think the way you're trying to do it here is correct.

Upvotes: 1

Related Questions