Conflicting If statements in For Loop

Hello,

I have a student working on a little dynamic movie. We have a sun, randomly duplicated clouds and some other stuff. The clouds move across the screen. When they hit the sun I would like the sky MC to switch to a gray color - I know how to do all of this. The problem lies in how to code the if statement so it doesnt conflict. Let me show the code and then I will explain more.

[AS]onClipEvent (enterFrame) {
for (var i = 0; i<=31; i++) {
if (this.hitTest("_root.clouds"+i)) {
_root.sky.gotoAndStop(“cloudy”);
} else {
_root.sky.gotoAndStop(“sunny”);
}
}
//Close of For Loop
}
[/AS]

Lets say clouds10 and clouds11 is on the stage. The sun hits cloud10 and “cloudy” triggered BUT at the same time the sun is NOT hitting cloud11 so the “sunny” is triggered and over rides the “cloudy”

How do I fix this. . there must be some simple trick I am missing.

Thanks Folks!

[AS]onClipEvent (enterFrame) {
for (var i = 0; i<=31; i++) {
if (this.hitTest("_root.clouds"+i)) {
_root.sky.gotoAndStop(“cloudy”);
cloudy = true;
break;
}
}
if (!cloudy) {
_root.sky.gotoAndStop(“sunny”);
}
cloudy = false;
//Close of For Loop
}[/AS]

dont you also want to evaluate “_root.clouds”+i? So it would be this:

onClipEvent (enterFrame) {
    for (var i = 0; i<=31; i++) {
        if (this.hitTest(_root["clouds"+i])) {
            _root.sky.gotoAndStop("cloudy");
            cloudy = true;
            break;
        }
    }
    if (!cloudy) {
        _root.sky.gotoAndStop("sunny");
    }
    cloudy = false;
    //Close of For Loop
}

well spotted yes it should be that. i didnt bother to check :whistle: i think i need a good strong coffee…

//ted goes of to find a coffee so strong the spoon stands up in it!

:lol:

You guys are GREAT! I appreciate the help.

Thanks,
Tobias