1

I am assigning colors to movie clips when buttons are clicked. These movie clips are vector shapes contained within an oval shape imported from Illustrator.

Each oval has a top color, a bottom color and an edge/rail color. I want the edge color to change to a combination of the top & bottom colors based on the selection of the bottom color.

I have been trying to use a conditional statement (at the bottom of the following code) with colorTransform to do this, but am not having any luck. Any tips??

(I've included an image below to help visualize what I'm trying to do.)

//Define Red Colors
var red1:ColorTransform = new ColorTransform();
red1.color = 0xE66B5B;

//Define Blue Colors
var blue1:ColorTransform = new ColorTransform();
blue1.color = 0x00467F;

//Define Red/Blue Edge Color
var redBlue:ColorTransform = new ColorTransform();
redBlue.color = 0x1D113F;

//toggle red top colors
redDeck_btn.addEventListener(MouseEvent.CLICK, toggleRedDeck);
function toggleRedDeck(e: MouseEvent) {
    deckColor_mc.transform.colorTransform = red1;
}

//toggle blue bottom colors
blueBtm_btn.addEventListener(MouseEvent.CLICK, toggleBlueBtm);
function toggleBlueBtm(e: MouseEvent) {
    btmColor_mc.transform.colorTransform = blue1;
    
    //deck = red, rails = purple color
    if (deckColor_mc.transform.colorTransform == red1){
    deckRail1_mc.transform.colorTransform = redBlue;
    btmRail_mc.transform.colorTransform = redBlue;
        }else{
            deckRail1_mc.transform.colorTransform = redBlue;
            btmRail_mc.transform.colorTransform = redBlue;
            }
}

enter image description here

bjonesin
  • 11
  • 1
  • Check also if my `blendRGB` function (blends between two colours) is useful to you: https://stackoverflow.com/a/71553488/2057709. If you give it the two top & bottom colours as function inputs, then you'll get a new blended colour (number) back for using as the rail's colour. – VC.One Apr 06 '22 at 01:39

1 Answers1

1

You need to compare the color property of the colorTransform Objects, like so:

deckColor_mc.transform.colorTransform.color == red1.color
Patang
  • 314
  • 2
  • 8
  • 2
    The exact reason of why direct comparison of `colorTransform` doesn't work is that they are objects, and object equality is compared by pointers. Setting a color transform to an object actually modifies the nested `colorTransform` property instead of assigning a link, thus comparing color transforms always returns false. – Vesper Mar 31 '22 at 09:20