简体   繁体   中英

AS3 Check if two movie clips are the same colour?

I'm trying to make a connect the dots game and I've run into a snag.

How can I check if two movieclips are the same colour? Using colorTransforms, I've made it so that when you hover over one dot it turns green and if you hover over the next correct dot, that dot also turns green and the rest remain red.

When the two dots are the same color (Green), I want a function that changes the line connecting both dots to visible. How would I write the conditional statements?

Here is my code:

line1.visible = false;

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

var green:ColorTransform = new ColorTransform();
green.color = 0x00FF00;

dot1.addEventListener(MouseEvent.MOUSE_OVER, color1Toggle, false, 0, true);
dot2.addEventListener(MouseEvent.MOUSE_OVER, color2Toggle, false, 0, true);

function color1Toggle(event:Event):void{
    dot1.transform.colorTransform = green;
    dot2.transform.colorTransform = red;
}

function color2Toggle(event:Event):void{
    dot2.transform.colorTransform = green;
}

So when dot1 and dot2 are green, I want line1's visibility to change to true.

Any suggestions? Thanks :)

function color1Toggle(event:Event):void{
    dot1.transform.colorTransform = green;
    dot2.transform.colorTransform = red;
    checkSameColors()
}

function color2Toggle(event:Event):void{
    dot2.transform.colorTransform = green;
    checkSameColors()
}

function checkSameColors():void {
    if (dot2.transform.colorTransform.color ==   dot1.transform.colorTransform.color) {
       //same color
       if (dot1.transform.colorTransform.color == 0x00FF00   ) {
          //both are 0x00FF00
           line1.visible = true;
       }
    }
}

This is not generic code but it answer your question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM