2 Replies Latest reply on Feb 5, 2014 12:03 PM by MadMich

    Layers

    MadMich Level 1

      I am trying to show/hide a layer and a field at the same time.

      This is what i have so far but i'm stuck as the field doesn't do anything!

       

      var ocgs = this.getOCGs();

       

          for (var i=0; i<ocgs.length; i++)

       

      if (ocgs[i].name == "MyLayer"){

                  ocgs[i].state = !ocgs[i].state;

       

      this.getField("MyField").display = display.visible;

       

      }else{

         

      this.getField("MyField").display = display.hidden;

      }

       

      Any pointers would be appreciated.

        • 1. Re: Layers
          Karl Heinz Kremer Adobe Community Professional

          Your field is actually doing something, but so fast that you may not see

          the effect. You are processing all layers in your loop, and whatever the

          last layer is determines if your field is shown or not. If your last layer

          is "My Layer", then you will see the field, if it's a different layer, your

          loop will end with the "else" path, and your field will get hidden. you

          need to modify the way your field gets shown or hidden:

           

          var ocgs = this.getOCGs();

           

          for (var i = 0; i < ocgs.length; i++) {

           

          if (ocgs[i].name == "MyLayer") {

           

          ocgs[i].state = !ocgs[i].state;

           

          if (ocgs[i].state) {

           

          this.getField("MyField").display = display.visible;

           

          } else {

           

          this.getField("MyField").display = display.hidden;

           

          }

           

          }

           

          }

           

          In this case, you are only modifying the field display property when your

          loop is processing the "MyLayer" layer.

           

           

          Karl Heinz Kremer

          • 2. Re: Layers
            MadMich Level 1

            Thank you very much that worked a treat.