# Strange If Else behaviour

**URL:** <https://forum.kirupa.com/t/strange-if-else-behaviour/286980>\
**Category:** flash\
**Created:** [April 23, 2009, 10:00pm UTC](https://forum.kirupa.com/t/strange-if-else-behaviour/286980 "2009-04-23T22:00:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![repticon](https://avatars.discourse-cdn.com/v4/letter/r/c6cbf5/32.png) [@repticon](https://forum.kirupa.com/u/repticon)\
**Post date:** [April 23, 2009, 10:00pm UTC](https://forum.kirupa.com/t/strange-if-else-behaviour/286980/1 "2009-04-23T22:00:22Z")

</div>

Hi guys. For some reason my written if else statements are not acting like they normally do. I’m either missing a piece of code or over looking something. Either way at this minute I’ve been trying to work it out for the past 2 hours with no success. If you can help that would be great.

It is working correctly from 0-3 1-2 but when it comes to 2-1 in output it keeps saying 2. Also for xbtn2 it skips 2 and goes straight to 1 on clicking xbtn1, even though 3-2 isn’t entered. I don’t know if this will make sense to anyone, but if it does any help would be appreciated. Please find below the code.

Thanks for reading.

\_global.imageNumber=0;

xbtn1.onRelease=function() {

```
if (_global.imageNumber==0) {
    imageHolder.gotoAndStop(imageNumber=3);
    
    } else if (_global.imageNumber==1) {
   imageHolder.gotoAndStop(imageNumber=2);
   
   } else if (_global.imageNumber==2) {
   imageHolder.gotoAndStop(imageNumber=1);

```

}  
\_global.imageNumber=1;  
trace(imageNumber);  
}

xbtn2.onRelease=function() {

```
if (_global.imageNumber==0) {
imageHolder.gotoAndStop(imageNumber=2);

 } else if (_global.imageNumber==1) {
   imageHolder.gotoAndStop(imageNumber=2);

} else if (_global.imageNumber==2) {
   imageHolder.gotoAndStop(imageNumber=3);

```

}  
\_global.imageNumber=2;  
trace(imageNumber);  
}
