View Full Version : Changing Colour Of A MC With A Colour Picker???
popnfresh24
August 17th, 2009, 11:07 AM
Hello all... i have a background and i want to be able to change the colours of it using a colour picker... if the MC was to cover the whole stage... how could i then get a colour picker and make it so it would change to whatever colour i wanted from the colour picker???
creatify
August 17th, 2009, 01:26 PM
one way if you want to use a component:
// open Window > Components
// drag the User Interface > ColorPicker component into your library
import fl.controls.ColorPicker;
import flash.geom.ColorTransform;
import fl.events.ColorPickerEvent;
var cp:ColorPicker = new ColorPicker();
cp.addEventListener(ColorPickerEvent.CHANGE, onSelectColor);
cp.colors = [ 0xFF0000,
0xCCCCCC,
0xCC0000,
0x123456,
0xFF6622,
0x333333];
addChild(cp);
var sp:Sprite = new Sprite();
with(sp.graphics) {
beginFill(0x000000);
drawRect(0,0,400,400);
endFill();
}
sp.x = sp.y = 100;
addChild(sp);
function onSelectColor(e:ColorPickerEvent):void {
var ct:ColorTransform = sp.transform.colorTransform;
ct.color = cp.selectedColor;
sp.transform.colorTransform = ct;
}
creatify
August 17th, 2009, 03:14 PM
also there is a sample of drawing a full-color swatch gradient here (http://www.boostworthy.com/blog/?p=200)
using the color transform above to change the color of your clip, you could draw a gradient to the stage and use bitmapData.getPixel(x,y) to get the color of a pixel in the swatch and color you clip that way.
popnfresh24
August 18th, 2009, 01:56 AM
when i use your code i get this error...
"1046: Type was not found or was not a compile-time constant: ColorPickerEvent."
popnfresh24
August 18th, 2009, 02:04 AM
nevermind... i worked it out lol
popnfresh24
August 18th, 2009, 02:24 AM
yay... it all works... i didn't use the bitmap thing or whatever... i just used this code instead
import fl.controls.ColorPicker;
import fl.events.ColorPickerEvent;
var currentColor:uint = 0xCC0000;
colorSquare.addEventListener(ColorPickerEvent.CHAN GE, colorChanged);
function colorChanged(cpevt:ColorPickerEvent):void {
currentColor = cpevt.color;
var ct:ColorTransform = cat.transform.colorTransform;
ct.color = colorSquare.selectedColor;
cat.transform.colorTransform = ct;
}
colorSquare.selectedColor = currentColor;
though i might end up using the gradient thing you showed me... thank you
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.