3 Replies Latest reply on May 1, 2006 3:59 PM by Newsgroup_User

    Varialbe into a path name?

    Level 7
      I am having the following issue and can't seem to figure it out. Thank
      you for anyone helping me with this.

      I have a MC containing my navigation with an instance name of nav.
      I have 4 buttons inside that with the instance names of p1, p2, p3 and p4.

      At some point I turn of all buttons like so:

      function disableBtns(){
      //disable the buttons
      nav.p1.enabled = false;
      nav.p2.enabled = false;
      nav.p3.enabled = false;
      nav.p4.enabled = false;
      }

      Then later on, I want to turn them back on, except for the one that was
      clicked and whos section is now open.

      function enableBtns(){
      //enable the buttons after the opening sequence
      nav.p1.enabled = true;
      nav.p2.enabled = true;
      nav.p3.enabled = true;
      nav.p4.enabled = true;

      //disable the one whos section currently in
      nav.btnDis.enabled = false;
      }

      The buttons have the following AS, except each one has a different
      number, i.e. p1, p2, p3...:
      nav.p1.onRelease = function() {
      contentBehaviors();
      btnDis = p1;
      };


      contentBehaviors() is just a function that goes through some steps, the
      last one of which is to trigger the enableBtns function.

      So why does this not work?
      The problem seems to be the
      nav.btnDis.enabled = false;
      where I am not getting the button name into the path correctly.
      What do I need to do?

      Thank you to everyone, who has helped me with this earlier. Sorry to be
      so slow on this...


      Thank you,
      Brian
        • 1. Re: Varialbe into a path name?
          Bishop[Neo]
          Your getting there, sort of

          Couple of changes.
          1. change nav.btnDis.enabled = false; to read nav[btnDis].enabled = false;

          2. change the code in the buttons to read:
          nav.p1.onRelease = function() {
          btnDis = "p1";
          contentBehaviors();
          };


          Note the order. I'm assuming you want to disable the button that was just clicked on, and that's what this code does. Other wise it won't disable until you click the *next* button. Also note that the button is surrounded by quotes. That means your assigning btnDis the value of "p1", a string. Then, when you call it in enableBtns() using the line I gave you above your referencing the string "p1" as an object (hence the [ ]'s ).

          Let me know how it turns out.

          Just for fun here is the entire AS code I used to test with. I placed 4 buttons in a clip named nav, put the nav clip on a blank stage and pasted the following AS into frame 1 of _root:

          function disableBtns(){
          //disable the buttons
          nav.p1.enabled = false;
          nav.p2.enabled = false;
          nav.p3.enabled = false;
          nav.p4.enabled = false;
          }

          function enableBtns(){
          //enable the buttons after the opening sequence
          nav.p1.enabled = true;
          nav.p2.enabled = true;
          nav.p3.enabled = true;
          nav.p4.enabled = true;
          nav[btnDis].enabled = false;

          }

          nav.p2.onRelease = function() {
          btnDis = "p2";
          contentBehaviors();
          };

          nav.p1.onRelease = function() {
          btnDis = "p1";
          contentBehaviors();
          };

          nav.p3.onRelease = function() {
          btnDis = "p3";
          contentBehaviors();
          };

          nav.p4.onRelease = function() {
          btnDis = "p4";
          contentBehaviors();
          };

          function contentBehaviors(){
          enableBtns()
          }
          • 2. Re: Varialbe into a path name?
            Level 7
            Bishop[Neo],
            man, I am sure it is just something so little that is wrong, but just
            does not work. I don't understand how you can disable just one button,
            using nav.enabled = false; Wouldn't that disable all of the navs? Well
            in my case it does none, I guess.

            here is the whole AS I have, maybe you know what is wrong?



            stop();

            //variable to test for the state of the nav
            fLocation = "navClosed"

            function contentBehaviors(){
            if(fLocation == "navClosed"){
            trace("nav is closed");
            _root.gotoAndPlay("open");
            }else if(fLocation = "navOpen"){
            trace("nav is open");

            //disable the buttons
            disableBtns();

            myText.tween('_alpha', 0, 0.2, 'linear', 0);
            //following line is just used for the callback
            subtitles.tween('_alpha', 100, 0, 'linear', 0.2, subtitlesCBclosed);
            images.tween('_alpha', 0, 0.2, 'linear', 0.4);

            //following line is just used for the callback
            subtitles.tween('_alpha', 100, 0, 'linear', 0.6, setNewContent01);

            images.tween('_alpha', 100, 0.2, 'linear', 1.2);
            //following line is just used for the callback
            subtitles.tween('_alpha', 100, 0, 'linear', 1.4, subtitlesCBopen);
            myText.tween('_alpha', 100, 0.2, 'linear', 1.6);

            //enable the buttons
            //following line is just used for the callback
            subtitles.tween('_alpha', 100, 0, 'linear', 1.8, enableBtns);
            }
            }


            function disableBtns(){
            //disable the buttons
            nav.b1.enabled = false;
            nav.b2.enabled = false;
            nav.b3.enabled = false;
            nav.b4.enabled = false;
            //set them to their original state/size
            nav.b1.tween('_width', 50, 1, 'easeOutElastic', 0);
            nav.b1.tween('_height', 56.8, 1, 'easeOutElastic', 0);
            nav.b2.tween('_width', 53, 1, 'easeOutElastic', 0);
            nav.b2.tween('_height', 60.2, 1, 'easeOutElastic', 0);
            nav.b3.tween('_width', 55, 1, 'easeOutElastic', 0);
            nav.b3.tween('_height', 60.2, 1, 'easeOutElastic', 0);
            nav.b4.tween('_width', 55, 1, 'easeOutElastic', 0);
            nav.b4.tween('_height', 60.2, 1, 'easeOutElastic', 0);
            }

            function enableBtns(){
            //enable the buttons after the opening sequence
            nav.b1.enabled = true;
            nav.b2.enabled = true;
            nav.b3.enabled = true;
            nav.b4.enabled = true;

            //disable the one whos section currently in
            //nav.enabled = false;
            nav.btnDis.enabled = false;
            //nav.enabled = false;
            //btnDis.enabled = false;
            trace("test ab ab --- btnDis is " + btnDis);
            trace("test ab ab --- contentp is " + contentp);
            }


            //following two functions change the Menuitems over and out states
            function buttonActionOver(theMC, theW, theH){
            theMC.tween('_width', theW, 1, 'easeOutElastic', 0);
            theMC.tween('_height', theH, 1, 'easeOutElastic', 0);
            }
            function buttonActionOut(theMC, theW, theH){
            theMC.tween('_width', theW, 1, 'easeOutElastic', 0);
            theMC.tween('_height', theH, 1, 'easeOutElastic', 0);
            }

            // Button 01
            nav.b1.onRelease = function() {
            contentp = "p1";
            btnDis = "b1";
            contentBehaviors();
            };
            nav.b1.onRollOver = function() {
            buttonActionOver(nav.b1, 55, 61.8);
            };
            nav.b1.onRollOut = function() {
            buttonActionOut(nav.b1, 50, 56.8);
            };

            // Button 02
            nav.b2.onRelease = function() {
            contentp = "p2";
            btnDis = "b2";
            contentBehaviors();
            };
            nav.b2.onRollOver = function() {
            buttonActionOver(nav.b2, 58, 65.2);
            };
            nav.b2.onRollOut = function() {
            buttonActionOut(nav.b2, 53, 60.2);
            };
            • 3. Re: Varialbe into a path name?
              Level 7
              Hey Bishop,
              thank you so much for your help. I just figured it out, I mean, I just
              finally understood what Luigi was trying to tell me and I could not see.
              I missed the brakets.
              This is what did it.

              nav[btnDis].enabled = false;

              Thank you so much for all your help!!!!!!!!!!!!!!
              Brian