Array of objects

  1. 3 months ago

    Is it possible to create an array of existing buttons? I did with Images, but couldn't do with Buttons.
    What i am trying to do is change buttons states in realtime. For example, i stored the buttons that are selected (1, 20, 32, 45), then when i reload that page i will have to select them again. Instead of do a big IF STATEMENT, i want to select by array (but):

    but[num].selected=true;

  2. marco

    Mar 22 Administrator User since 2016

    Yes it possible:

    1. add an ivar to the window, for example r = [];
    2. add your buttons to r with r.push(Button1); ...r.push(ButtonN);
    3. r[index] will represent a button and you can call the .selected = true method
  3. i have to add using push, i can't do something like r = [Button1, Button2... , ButtonN]?

  4. marco

    Mar 22 Administrator User since 2016

    Oh yes sure you can do that too

  5. Edited 3 months ago by Luiz D'Aniello

    thanks @marco
    I tried, but give an error. looks like isn't stored an object.

    Runtime error: Unable to find backgroundColor into class Int

    Source: teste[0].backgroundColor=Color("fedd43");

  6. Hi @marco,
    not sure if it's a bug or it was supposed to be like that, if i try:

    var but=[but1,but2,but3];
    but[0].backgroundColor=Color("FF0000");

    give me the error above. BUT if i try:

    var but=[but1,but2,but3];
    var x=but[0];
    x.backgroundColor=Color("FF0000");

    goes fine

  7. marco

    Mar 25 Administrator User since 2016

    You are right, it was a codegen bug (already fixed in our build).
    As a temporary workaround you can write:

    (but[0]).backgroundColor=Color("FF0000");

    This bug will be fixed within the next upcoming release.

or Sign Up to reply!