# Conflicting If statements in For Loop

**URL:** <https://forum.kirupa.com/t/conflicting-if-statements-in-for-loop/183099>\
**Category:** Uncategorized\
**Created:** [March 23, 2006, 8:13pm UTC](https://forum.kirupa.com/t/conflicting-if-statements-in-for-loop/183099 "2006-03-23T20:13:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tgelston](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/tgelston/32/54_2.png) [@tgelston](https://forum.kirupa.com/u/tgelston)\
**Post date:** [March 23, 2006, 8:13pm UTC](https://forum.kirupa.com/t/conflicting-if-statements-in-for-loop/183099/1 "2006-03-23T20:13:08Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Macaroni\_Ted](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Macaroni\_Ted](https://forum.kirupa.com/u/Macaroni_Ted)\
**Post date:** [March 25, 2006, 2:39am UTC](https://forum.kirupa.com/t/conflicting-if-statements-in-for-loop/183099/2 "2006-03-25T02:39:58Z")

</div>

[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]

---

<div class="post-metadata">

**Author:** ![freeskier89](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@freeskier89](https://forum.kirupa.com/u/freeskier89)\
**Post date:** [March 25, 2006, 2:53am UTC](https://forum.kirupa.com/t/conflicting-if-statements-in-for-loop/183099/3 "2006-03-25T02:53:10Z")

</div>

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

```auto
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
}

```

---

<div class="post-metadata">

**Author:** ![Macaroni\_Ted](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Macaroni\_Ted](https://forum.kirupa.com/u/Macaroni_Ted)\
**Post date:** [March 25, 2006, 3:07am UTC](https://forum.kirupa.com/t/conflicting-if-statements-in-for-loop/183099/4 "2006-03-25T03:07:10Z")

</div>

> [@freeskier89](#):
>
> dont you also want to evaluate “\_root.clouds”+i? So it would be this: ActionScript Code:

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!_

---

<div class="post-metadata">

**Author:** ![freeskier89](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@freeskier89](https://forum.kirupa.com/u/freeskier89)\
**Post date:** [March 25, 2006, 3:07am UTC](https://forum.kirupa.com/t/conflicting-if-statements-in-for-loop/183099/5 "2006-03-25T03:07:56Z")

</div>

:lol:

---

<div class="post-metadata">

**Author:** ![tgelston](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/tgelston/32/54_2.png) [@tgelston](https://forum.kirupa.com/u/tgelston)\
**Post date:** [March 27, 2006, 6:37pm UTC](https://forum.kirupa.com/t/conflicting-if-statements-in-for-loop/183099/6 "2006-03-27T18:37:09Z")

</div>

You guys are GREAT! I appreciate the help.

Thanks,  
Tobias
