Is it possible to loop through an array to check if certain buttons are visible?
Copy link to clipboard
Copied
Sorry, I know this may be a weird question:
I know how to loop through sequentially to hide all buttons. This is what I've used:
for (var i = 1; i < 54; i++) {
getField("Button" + i).display = display.hidden;
}
and that works fine for me.
Where I'm stuck is I'd like to use an if statement to cycle through a random list of the buttons to check if they are visible or not visible. I know you can declare array variables, but I have no idea how to implement all of this.
I know I could type it all in, but I'd like to reuse this with maybe different button numbers at some point, so i'd just like to change the array.
Say for sake of argument I'd like the if statement to check if Button2, Button3, Button5,Button9, Button18 and Button 46 are visible and that all the other buttons up to 53 are hidden.
Is this possible without doing the following and having to type it for every button:
if(this.getField("Button1").display=display.hidden && this.getField("Button2").display=display.visible &&
this.getField("Button3").display=display.visible &&
this.getField("Button4").display=display.hidden //ETC ETC
I hope that makes sense? Any help gratefully received!
Copy link to clipboard
Copied
About arrays in Javascript:
Copy link to clipboard
Copied
Hi,
Depending on how many fields you have (that are not buttons) you might be able to use. This gets all the fields in a document and then checks if they are buttons, once you know it is a button you could code to allow for above
for ( var i = 0; i < doc.numFields; i++){
var curField = doc.getField(doc.getNthFieldName(i));
if ( curField.type == "button"){
// do some logic to work out if it is hidden or not
}
}
Regards
Malcolm

