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

flash actionscript : Multiple color objects - an easier way?


cconcannon
3/17/2004 10:18:39 PM
I have a movie in which I have several movie clips that need to change to
different colors all at once (I'm using a slider bar). All the examples I can
find only use one movie clip. Do I have to set up a new color object and
define all 8 attributes for every movie clip?
Please tell me there is a more efficient way to do this?!?
EX)
//create new objects for each movie clip
colorObj1= new Object();
colorObj2 = new Object();
....
colorObjn = new Object();

// define settings for each new object
colorObj1.ra = 50;
colorObj2.ra = 80;
....
colorObjn.ra = 20;

// create color object for each movie clip
color1 = new Color(clip1_mc);
color2 = new Color(clip2_mc);
.....
colorn = new Color(clipn_mc);

//Assign new colors to each movie clip
color1.setTransform(colorObj1);
color2.setTransform(colorObj2);
...
colorn.setTransform(colorObjn);

pazzoboy
3/18/2004 2:22:58 AM
How about adding a 2nd frame to each movieclip, with the color changed in the 2nd frame.
Then,
for(x=1;x<=n;x++){
eval("mc"+x).gotoAndStop(2);
cconcannon
3/18/2004 2:15:53 PM
Not a bad idea, pazzoboy, but in this case I need the colors to change
gradually with the slider. For example a red MC to fade to orange and an
yellow MC to fade to green, etc. Jumping a frame would make a hard color
switch.
I figured maybe there is some way to set up a child object from the Color
object, but I'm not sure how or if it's possible.

-C
pazzoboy
3/18/2004 3:28:12 PM
Okay, I came up with this, but it seems to be quirky. Maybe someone else can
tell me why...it doesn't change gradually when I drag the slider (graphics are
ugly, but concentrating on code, sorry). So, I have two MC's, "1" and "2", and
a slider called "slider". Here's what is on the main timeline:

setProperty(slider,_x,0); //put the slider bar at zero.
colorArray=new Array("0x000000","0x000033","0x000066","0x000099",
"0x0000ff","0x330000","0x660000","0x990000","0xff0033","0xff0066",
"0xff0099","0xff00ff","0xff3333","0xff3366","0xff3399","0xff33ff",
"0xff66ff","0xff99ff","0xffffff","0xff3300","0xff6600","0xff9900","0x666666",
"0x999999","0xcccccc"); //the array of available colors
slider.onRelease=function(){
slider.startDrag(); //drag the slider bar
};
this.onEnterFrame=function(){
sliderX=slider._x; //catch the horizontal position of the slider
setProperty(slider,_y,30); //keep the slider from dragging up and down
for(x=0;x<25;x++){
if(sliderX==x){
myColor1 = new Color(1);
myColor1.setRGB(colorArray[x]);
myColor2 = new Color(2);
myColor2.setRGB(colorArray[x]);
}
}
};

The colors don't change gradually, even though I have just one frame, and
frame rate is 40. Any hints out there? Is setRGB just a taxing method?
pazzoboy
3/18/2004 3:43:59 PM
Okay, I did what every good flasher should do: I traced sliderX. Of course
sliderX will rarely == 0 through 24, so the colors wouldn't change that often.
Why? Because I didn't include the Math.floor method to squash the decimals.
Here's the working code:

colorArray=new
Array("0x000000","0x000033","0x000066","0x000099","0x0000ff","0x330000","0x66000
0","0x990000","0xff0033","0xff0066","0xff0099","0xff00ff","0xff3333","0xff3366",
"0xff3399","0xff33ff","0xff66ff","0xff99ff","0xffffff","0xff3300","0xff6600","0x
ff9900","0x666666","0x999999","0xcccccc");
slider.onRelease=function(){
slider.startDrag();
};
this.onEnterFrame=function(){
sliderX=Math.floor(slider._x);
trace(sliderX);
if(sliderX<0){slider.stopDrag();setProperty(slider,_x,0);}
setProperty(slider,_y,30);
for(x=0;x<25;x++){
if(sliderX==x){
myColor1 = new Color(1);
myColor1.setRGB(colorArray[x]);
myColor2 = new Color(2);
myColor2.setRGB(colorArray[x]);
}
}
};
stop();
jolyon_russ
3/18/2004 5:13:55 PM
I suggest you read up on setTransform

This allows you set the percentage of R, G, B and Alpha (-100 to 100) as well
as the offset (-255 to 255)

This will allow you to get a VERY gradual change in colour, I created a
simular looping effect using Math.sin to create random RGB values.

Hope this helps


Jolyon
cconcannon
3/18/2004 7:28:12 PM
That's exactly what I was trying to use, and that's exactly why I posted the
question. I'm just trying to find out if there is a better way to handle 6 to
8 color objects at once instead of setting the values for 64 different values
(.ra through aa * 8).
At the moment I've tried using the keyframe method pazzoboy first suggested.
It's quick and dirty and not exactly what I wanted, but a heck of a lot less
code.

-C
Pete Hughes
3/19/2004 7:15:47 PM
Maybe there is a color method at peterjoel.com that can help corral all of
those colors. You are still going to have to tell eight things what to do each
frame in which the slider has moved.

http://www.peterjoel.com/ActionScript/?go=color
AddThis Social Bookmark Button