8 Replies Latest reply on Jan 18, 2013 5:04 PM by Ned Murphy

    What am I doing wrong with the _ visibility property?

    zosaji Level 1

      I have an object that is a movie clip, and I want this object to disappear when you click on him, but also the button that makes the object to appear to make also the object to disappear.Either way, when you click on the object or on the button the second time, the same object to disappear.  I managed to do that, but the first time when you click the button in order to make the object appear it dosen't work, you have to click twice.What am I doing wrong? The object it's a movie clip named frez1, and the button is named fr1. I put this codes in the main timeline:   for the movie clip :           frez1.onPress = function(){                                      _root.frez1.gotoAndStop(2);                                      _root.frez1.gotoAndStop(1);                                           }  for the button:          frez1._visible = false;                                     fr1.onRelease = function(){                                  frez1._visible = !frez1._visible;                              }   The button and the object are on different layers.  Thank you for your help.

        • 1. Re: What am I doing wrong with the _ visibility property?
          Ned Murphy Adobe Community Professional & MVP

          You should properly format the code in your posting to make it easier to try to help you.  Also, you

           

          There is nothing in the code you show that would make the frez1 movieclip's _visible property change when you click it, so that might be related to the problem you are experiencing.  Only the button is affecting the movieclip's visibility.

           

          If you click the button it will toggle the visibility on and off.

           

          Maybe whatever you do in making the movieclip switch between frames 1 and 2 has you thinking it is turning invisible. 

          1 person found this helpful
          • 2. Re: What am I doing wrong with the _ visibility property?
            zosaji Level 1

            Oh sorry, only now I have seen how it has been displayed. The codes are like this:  for the movie clip:  frez1.onPress = function(){                                     

                                                                                                                                                                        _root.frez1.gotoAndStop(2);

                                                                                                                                                                        _root.frez1.gotoAndStop(1);   

                                                                                                                                                                     }

                                                                                                                                          

                                                                                                                                              for the button:   frez1._visible = false;                                   

                                                                                                                                                                     fr1.onRelease = function(){                                 

                                                                                                                                                                     frez1._visible = !frez1._visible;                             

                                                                                                                                                                   }  

             

            Yes the movie clip switching between frames and 1-2 it is turning  him invisible.

            So in order to make him go between this two frames I have to put  the visibity property and not the root ?

             

            Thank you

            • 3. Re: What am I doing wrong with the _ visibility property?
              Ned Murphy Adobe Community Professional & MVP

              The first thing you should do is avoid unnecessary use of _root references.  If the code is in the timeline where the object exists, there is no need to reference the timeline (which in this case is the _root).

               

              Telling the movieclip to go to frame 2 immediately followed by telling it to go to frame 1 will have it always in frame 1.

               

              If you want to be able to click the movieclip to make it visible, then you cannot make it invisible because invisible objects do not interact with a mouse.  You need to change its _alpha property instead.  Try replacing all of the code you show with the following and eliminate the frames aspect of frez1...

               

              frez1._alpha = 0; 

               

              function toggleMC(){

                  if(frez1._alpha == 0) {

                      frez1._alpha = 100;

                  } else {

                      frez1._alpha = 0;

                  }

              }

               

              frez1.onRelease = fr1.onRelease = toggleMC;

              • 4. Re: What am I doing wrong with the _ visibility property?
                zosaji Level 1

                It's working,thank you,  also thank you for the explanations, it helps me a lot to learn :)

                • 5. Re: What am I doing wrong with the _ visibility property?
                  zosaji Level 1

                  I have another problem, I have multiple objects like frez1, it's frez2,3......etc. when I put the code on  that you gave me on them it dosen't work anymore, for example, I put the code on frez2, and only that one showed it to me even if I press the button for the frez1.

                  • 6. Re: What am I doing wrong with the _ visibility property?
                    Ned Murphy Adobe Community Professional & MVP

                    If you have several movieclip/button pairs then it might be easiest for you to understand if you write functions separately for each

                     

                    frez1.onRelease = fr1.onRelease = toggleFrez1;

                    frez2.onRelease = fr2.onRelease = toggleFrez2;

                    frez3.onRelease = fr3.onRelease = toggleFrez3;

                     

                    function toggleFrez1(){

                        if(frez1._alpha == 0) {

                            frez1._alpha = 100;

                        } else {

                            frez1._alpha = 0;

                        }

                    }

                     

                    function toggleFrez2(){

                        if(frez2._alpha == 0) {

                            frez2._alpha = 100;

                        } else {

                            frez2._alpha = 0;

                        }

                    }

                     

                    function toggleFrez3(){

                        if(frez3._alpha == 0) {

                            frez3._alpha = 100;

                        } else {

                            frez3._alpha = 0;

                        }

                    }

                    1 person found this helpful
                    • 7. Re: What am I doing wrong with the _ visibility property?
                      zosaji Level 1

                      It's working :D Thank you so much for taking the time to help me.