Recolor Sprite with solid color and tiling background

I’d like to know how I could recolor an existing display object (like a movieclip or sprite) dynamically. I want to let the user pick colors or patterns for the sprite from a color picker I’ve already programmed. I need to know first how to apply a new color to an existing sprite, and second how to apply a tiling pattern to it. Thanks in advance.

myColor = 0xFFFFFF
myColoredObject = new Color(object_name);
myColoredObject.setRGB(myColor);

The Color class is deprecated all the way back since Flash Player 8…

use flash.geom.ColorTransform

As usual, Adobe’s language reference is less than helpful on the topic. What’s the exact command I could use to reset a display object’s color, without any of the garbage about channels and RGB. I just want to know how to set the object’s color to a standard Flash-syntax RGB code, not how to set it’s R, G, and B values separately. Can anybody give me an example?

it’s right there in the docs… Colortransform.color(c:uint);

Well, I guess I must be incredibly dense, but I still don’t get it. I see lots of documentation, but I don’t understand how to apply it unless I can see an example. Their example doesn’t use the color() method. Here’s my code; it receives the new color from a custom event then sets the current movieClip’s color with it. This function is within the code for the MovieClip. It doesn’t work.


        
        private function onColorChanged(evt:ColorPickerEvent):void {
            this.ColorTransform(evt.newColor); 
            trace (evt.newColor);
        }

I’d really appreciate an example…


var m:ColorTransform = new ColorTransform();
m.color = 0xFF00FF;
box.transform.colorTransform = m;

:stuck_out_tongue:

var c:ColorTransform = new ColorTransform();
c.color = 0xFF0000;

mc.transform.colorTransform = c;

That makes mc red.

Pfft, I used cooler variable names

^^ m is obviously cooler than c.

m = manly, macho, moose, muscle, manhood, moolah

c = chickflick, chique, carnival, chihuahua.

Thanks for the examples guys; if I ever finish the project, I’ll post it somewhere.

I guess I should’ve tested it before thanking you; it doesn’t work. I have a class linked to an on-stage moveclip; this class listens for a custom event and that event triggers a function. Here’s the class

package classes {
	
	import flash.display.MovieClip;
	import flash.geom.*;
	import flash.events.*;
	
	public class MiniTruckSim extends MovieClip {
		public function MiniTruckSim():void {
			var cPicker:ColorPicker = new ColorPicker(stage);
			cPicker.addEventListener(ColorPickerEvent.COLOR_CHANGED, onColorChanged, false, 0, true);
		}
		
		private function onColorChanged(evt:ColorPickerEvent):void {
			var c:ColorTransform = new ColorTransform();
			c.color = evt.newColor;
			this.transform.ColorTransform = c;
		}
	}
}

… and here’s the error I get:
[pre]ReferenceError: Error #1056: Cannot create property ColorTransform on flash.geom.Transform.
at classes::MiniTruckSim/::onColorChanged()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at ColorPicker/::setTruckColor()
at ColorPicker/::onClick()[/pre]
I’ll see if my new AS3 book has anything to say on the subject.

Sage_of_Fire I have class that work in same way like in AS2.0 plus new features
check my [U]blog[/U] RichColor class. P.S. u can ser R,G,B values separately :).

this.transform.ColorTransform = c;

should be

this.transform.colorTransform = c;

Read the examples before you try something.

Sorry, rookie mistake. The typos alllllways get me…