Question

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 :)

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top