Groups | Blog | Home
all groups > flash actionscript > march 2006 >

flash actionscript : Replace Colors in a movie clip


mostlyliquid
3/30/2006 1:19:08 PM
Na you can do that. Make the color(s) you want to chagne into movie
clips, and give them instance names. then to chage color, do somethign
like this:

myColor = new Color(_root.clip1.subClip);
myColor.setRGB(0x333333);

You can put that in a function or whatever. Just put a path to the
subclip in the parenthesis above. Then put the hex value in setRGB
preceded by 0x. Also double check, i cant remember if the hex has to be
in quotes and dont have flash open. Look into the color class for more
info - HTH.

-J
tralfaz
3/30/2006 1:31:00 PM

[quoted text, click to view]

Did you forget about colorTransform?
http://members.cox.net/4my5cats/colorTransform.html
tralfaz

tralfaz
3/30/2006 2:20:33 PM

[quoted text, click to view]

It's a tricky thing I think because if each object has only one color of red, green, or blue (not a mix), then it's easy to reduce
or increase just that color, but if each object is a mix of colors then changing one of the rgb settings will affect the color in
both objects. Well, maybe colorTransform will help, depending on the effect that was needed.
Anyway, I thought you might have been thinking of setRGB which would flat color the object, not just adjust it from where it's at
now.
tralfaz

tralfaz
3/30/2006 2:27:39 PM
[quoted text, click to view]

I would have to see the original and try the numbers. You can download that example and replace the kitty picture with your
movieclip, then play around with the sliders.
Because white is a mix of all 3 colors ..rgb, lowering any of them will reduce the white to a gray. You can do like David Stiller
suggested and only color parts of the movieclip by making some sub-clips inside of it. so, let's say that myMovie has a white
color, and inside that movieclip you have a blue box that you changed to a movieclip bluebox. Then you could set up the color
object.. myColor = new Color(myMovie.bluebox);
Now your color transform would leave the white part alone and only change the color on the bluebox part.
tralfaz

David Stiller
3/30/2006 4:16:56 PM
rogz,

[quoted text, click to view]

Yes.

[quoted text, click to view]

Changing a movie clip's colors is an all-or-nothing thing. If a clip
has nested artwork -- whether graphic symbols or movie clip symbols -- your
whole clip, all of it, will become the color you set it to. It will look
like a colored silhouette. If you want to swap two colors inside a movie
clip, you'll have to make the inside items movie clips, too. Don't change
the movie clip that contains them; rather, change each of the clips inside.


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."

David Stiller
3/30/2006 5:01:16 PM
[quoted text, click to view]

Actually, I didn't ... but I wasn't nearly as clear as I could have
been. :) I like your example a lot -- in fact, I'm pretty sure I've seen
that page of yours before -- but even this doesn't give the OP what he or
she is looking for (I think). The color change is always uniform ... it
isn't possible to change only the red parts of an image or to swap the red
parts for the blue parts, etc. Not unless those parts are nested MCs and
you hit those each, instead.

Really, though, you may have nailed it. Maybe I don't understand the
OP's question.

[quoted text, click to view]

colorTransform is a more granular way of changing color (and opacity) of
a movie clip, but it's still an all-or-nothing deal. Applying a change to
your movie will adjust everything it contains, not just certain colors
inside it.


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."

David Stiller
3/30/2006 5:03:18 PM
[quoted text, click to view]

And actually, that statement is probably incorrect now, given the new
BitmapData class. I really need to study that one. Still, using that to
change certain colors in a movie clip ... much more complicated. And
actually, you're not really touching a movie clip at that point, but an
actual image.


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."

mostlyliquid
3/30/2006 5:50:02 PM
Thats what i thought too, sorry if i misguided you. If you can break
the movie clip into distinct subclips and give each an instance name,
you can set colors for each of them. Im not sure what kind of picture
you have tho. Can you post something?

Not to state the obvious, but another, less efficient way to do this
would be to mod your image in photoshop, then just tween or transition
between the two in flash. You can use something like select/color range
and tweak it there, then import it as another movie clip. If you are
only doing this once the hit may be acceptable, but if you want a
reusable bit of code that will apply color transforms to different
clips, that may get a bit heavy. HTH.

-J
rogz
3/30/2006 9:04:57 PM
Is it possible to replace colors in a movieclip through actionscript. I have a
movie clip that contains some blue and white and i want to swap the blue with
red...can i do this or do i need to go the route of reloading the movie clip
with images?
rogz
3/30/2006 9:54:30 PM
i have a movie clip with some white and blue in it. what i want to do is change
the blue to the following color FF9900...i can get the settransform to sort of
work but the orange color seems a little faded and is not as rich as it should
be...any ideas? i'm currently using the following code:

myColor = new Color(myMovie);
myColorTransform = new Object();
myColorTransform = { ra: '100', rb: '255', ga: '100', gb: '153', ba: '100',
bb: '0', aa: '0', ab: '100'};
myColor.setTransform(myColorTransform);
kglad
3/31/2006 2:17:22 AM
if your movieclip has instance name mc1, you can use the following code to
replace 0x0000ff in mc1 with FF9900:


import flash.display.BitmapData;
bmp = new BitmapData(mc1._width, mc1._height, true, 0xcccccccc);
_root.createEmptyMovieClip("holderMC", 1);
bmp.draw(mc1);
holderMC.attachBitmap(bmp, 1);
for (var x = 0; x<=mc1._width; x++) {
for (var y = 0; y<=mc1._height; y++) {
c = bmp.getPixel(x, y);
if (c.toString(16)==0000ff) {
bmp.setPixel(x, y, 0xffFF9900);
}
}
}
AddThis Social Bookmark Button