Strange If Else behaviour

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);
}