# Button problems

**URL:** <https://forum.kirupa.com/t/button-problems/188463>\
**Category:** Uncategorized\
**Created:** [May 8, 2006, 6:14am UTC](https://forum.kirupa.com/t/button-problems/188463 "2006-05-08T06:14:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![blacey777](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@blacey777](https://forum.kirupa.com/u/blacey777)\
**Post date:** [May 8, 2006, 6:14am UTC](https://forum.kirupa.com/t/button-problems/188463/1 "2006-05-08T06:14:25Z")

</div>

I have a page that is loading images from an XML file. There are both square buttons (button1, button2, etc) and arrow buttons (next\_btn, previous\_btn) to navigate through the images. Everything is working perfectly except for the fact that if a square button is pushed that is out of sequence (1-6), the next button does not recognize that and goes to the wrong image. I need the next button to recognize what the other buttons are doing and what image is currently being viewed not just the last image viewed by means of the next\_btn. Here is some code so that you can see what I’m talking about:

var p = 1;

//

for (var i = 1; i \<= 6; i++)

{

var button = eval(“button” + i);

button.i = i;

button.onPress = function()

{

resetAllButtons();

this.\_alpha = 100;

this.enabled = false;

if (loaded == filesize)

{

picture.\_alpha = 0;

picture.loadMovie(image[this.i - 1], 1);

desc\_txt.text = description[this.i - 1];

picture\_num();

}

// change the value of p

p == this.i -1 ;

};

}

// this appears outside the for() loop

listen = new Object();

listen.onKeyDown = function()

{

if (Key.getCode() == Key.LEFT)

{

prevImage();

}

else if (Key.getCode() == Key.RIGHT)

{

nextImage();

}

};

Key.addListener(listen);

previous\_btn.onRelease = function()

{

prevImage();

};

next\_btn.onRelease = function()

{

nextImage();

};

//

function nextImage() {  
if (p \< 6) {  
p++;  
} else {  
p = 1;  
}  
eval(“button” + p).onPress();  
}

function prevImage() {  
if (p \> 1){  
p–;  
} else {  
p = 6;  
}  
eval(“button” + p).onPress();  
}

function resetAllButtons()

{

for (var i = 1; i \<= 6; i++)

{

var button = eval(“button” + i);

button.\_alpha = 30;

button.enabled = true;

}

}
