0

So here I want to check the variable lineOpt1_1 against 9 other variables- varLine1_1, varLine1_2, ......varline1_9

If it matches one of these, I want to hide a button "Examples Button_1_1" (cp.hide is used for adobe captivate):

for (i = 0; i < 9; i++) {

    if (varLine1_[i] == lineOpt1_1) {

        cp.hide(Examples_Button_1_1);
    }
}

Could someone show me what I'm doing wrong? Thank you.

J. Titus
  • 9,535
  • 1
  • 32
  • 45
WTS14
  • 1

1 Answers1

0

You're trying to index an object, but not trying to access varLine1_X variables. As it's commented in the question, if these variables are global, there's no problem to get/index the global object with "varLine1_" + X:

window['varLine1_' + i]

If you want to do this using local variables, you'd need to use eval that parses/executes an code in the same scope where it has been called (this is also commented on the question).

eval('varLine1_' + i)

However it happens that these tricks make the code hard to work and understand. Try using objects / arrays (as commented, also):

var linesGroups = [
    [ 50 ]
];

// Confirm that the first element/prop "0" of linesGroups array
// is indexable
if (linesGroups[0])
    // Iterate each item of linesGroups[0]
    // if it's iteratable
    for (var item of linesGroups[0]) {
        if (item === lineOpt1_1) {
            cp.hide(Examples_Button_1_1);
        }
    };
  • Hi Someone, unfortunately I don't understand, but could I ask another question? This script works fine for my purposes- so I can see the variable is global. Since the integer at the end of the button ID "Examples_Button_1_x" is always the same as the integer at the end of the variable 'lineOpt1_x' - is there a way to add a second looped integer "j" to auto hide any button that ends wit the same integer as the "lineOpt1_" variable,so long as that "lineOpt1_" variable matches one of the varLine1_1 through varLine1_9 variables? – WTS14 Oct 26 '16 at 01:53
  • Something like: `for (var i = 0; i < 9; i++) { for (var j = 0; j < 20; j++) { if (window['varLine1_' + i]== window['lineOpt1_'+ j]) { cp.hide("Examples_Button_1_”+j); } } } – WTS14 Oct 26 '16 at 01:59
  • @WTS14 Can you do a resume ? –  Oct 26 '16 at 08:48