1

I am working on a game with colors. You got one object that gives a random color. Then you got 3 buckets for RGB and you need to mix the random given color in a new object. That works just fine. I also made a reset button, but that does not really work. If you click the reset button, it resets the right object with the random color. If you click the resetbutton again, your mixed color in the left object also resets. If you click the resetbutton, it should should reset both objects. But it it only resets the right and if you click it again the left. I really cant see an mistake of mine... so did anybody had a problem like this?

reset_button.addEventListener(MouseEvent.CLICK, reset);

function reset(event:MouseEvent):void{

    kreis.transform.colorTransform = my_color;
    my_color.blueOffset = 0;
    my_color.greenOffset = 0;
    my_color.redOffset = 0;

    kreis2.transform.colorTransform = my_color2;
    my_color2.blueOffset = 0;
    my_color2.greenOffset = 0;
    my_color2.redOffset = 0;
}
4

1 回答 1

0

尝试提取代码以调用其他 2 个函数

像这样

function reset(event:MouseEvent):void{
    reset_1();
    reset_2();
}
function reset1():void{
    kreis.transform.colorTransform = my_color;
    my_color.blueOffset = 0;
    my_color.greenOffset = 0;
    my_color.redOffset = 0;
}
function reset2():void{
    kreis2.transform.colorTransform = my_color;
    my_color2.blueOffset = 0;
    my_color2.greenOffset = 0;
    my_color2.redOffset = 0;
}
于 2013-09-16T06:48:19.850 回答