7 Replies Latest reply on Dec 13, 2007 8:48 AM by douggler

    Array Help


      I have this function which is supposed to enable my button movieclips all expect for one, which is passed as an argument, but it is not working correctly. All buttons are enabled but the one sent via the argument is not disabling.

      Can someone see what I am doing wrong please?

        • 1. Re: Array Help
          Level 7
          You are creating strings, not clip references.

          Try this:

          function enableNavigation(section)
          var btns = [home, interior_design, project_management, profile,
          people_new, projects, contact];
          for(var i = 0; i < btns.length; i++){
          btns .enabled = true;
          section.enabled = false;

          And call the function like enableNavigation(interior); not
          And function names should not begin with a capital letter - that is for

          Dave -
          Head Developer
          Adobe Community Expert

          • 2. Array Help
            BSpero Level 1
            You can't refer to the movie clips by just a string, the way you are doing it now. You need to use this[movieClipName]. The array is fine, although I would create it at the start of the movie, rather than each time the function is called. Also, you are not calling individual list items in your loop, but just "enabling" your list 7 times. To cycle through the array items you need something like:

            • 3. Re: Array Help
              douggler Level 1

              Using the method, when i attempt to trace(section); it always says section is undefined.

              I call the function as such:


              Any ideas?

              • 4. Array Help
                BSpero Level 1
                I think you're almost there. Do you have your stage instances all named the same as the names in the array? If not, that could cause the "undefined" to come up. Also it looks a problem is that you are not iterating through the code when you run your for loop. You need to add a reference to which item in the list you are referring to when you're enabling it. If you copied and pasted DM's code, then I am pretty sure his iterator was lost, and the message took it as an html tag, making his entry italic. You have:
                • 5. Re: Array Help
                  douggler Level 1
                  Thanks for the tip - the enabling/disabling works great now, however, the section being passed is still coming through as undefined, and all my stage instances are called the same as the array values.

                  As I say, I call the function like this:

                  _root.enableNavigation(interior_design); // this is called from an external SWF loaded into the main timeline

                  • 6. Array Help
                    BSpero Level 1
                    When you pass that variable, it uses whatever that variable is in the movie that sends it. Since your buttons are not defined in your external .swf, then it will pass an undefined value to the function. You either need to pass it the exact path of the movie clip (_root.interior_design probably) or a string of the name, which is what you were doing before. If you pass the string, then you need to refer to it a little differently in your function. Instead of:

                    section.enabled = false;

                    you would have to use ...

                    this[section].enabled = false;

                    I hope this isn't totally confusing. It takes a while to get used to paths and the scope of variables and functions.
                    • 7. Re: Array Help
                      douggler Level 1
                      Ah haaa!

                      The penny drops in my head! Cheers BSpero. I didnt even think to notice that the variable I am sending is undefined in my external swf - dur. I have sorted it thanks to your continued support.

                      Many Thanks.