4 Replies Latest reply on Mar 18, 2008 8:09 AM by yogi bear

    passing variable trouble

    yogi bear
      I have created a few arrays in a frame and am trying to pass a variable from the main array to choose a second array by passing a variable using a function after a button is clicked. I use this code to select the name of the new array:

      _root.m1[name].menuTwoID = homeMenu [0];

      from this array
      var homeMenu:Array = [["residential", "resMenu"], ["commercial", "comSubMenu"],.....

      That should produce a passed variable "resMenu" correct?

      It doesn't work later later in a new function when I put it into:
      _root.m2[name].main_text.text = menuTwoID[count-1][0];
      to get the names from the second array.

      If I put "resMenu" directly in the code (below) it works fine.
      _root.m1[name].menuTwoID = resMenu;

      Any ideas of what I'm doing wrong?

      Thanks
        • 1. Re: passing variable trouble
          robdillon Most Valuable Participant
          homeMenu[0] is "residential", "resMenu". If you just want resMenu then you want to ask for homeMenu[0][1].
          • 2. Re: passing variable trouble
            yogi bear Level 1
            That's right, good catch, typo on my part. I've tried that and still get undefined.
            Is it a scope issue or is something else going on when I try to pass it for the name
            of a new array and then add the rest of the array definition below?

            _root.m2[name].main_text.text = menuTwoID[count-1][0];

            Thanks, Text
            • 3. Re: passing variable trouble
              robdillon Most Valuable Participant
              It could be scope. You'll have to expain how and where you're using this code. You might also want to explain why you're using the array in the first place. If you just want to define values for some variables, there are simpler ways to accomplish this.
              • 4. Re: passing variable trouble
                yogi bear Level 1
                Here's an example of the idea:

                I create a menu and when it's clicked try to use the menuTwoID to pass the name of the new array to create a new sub menu. But that doesn't work. Is it that's it's a string and not an array?



                var AllColors:Array = [["reds", "colorsOne"], ["blues", "colorsTwo"]];
                var colorsOne:Array = [["Fire Engine", "colors1a"], ["Sunset", "colors1b"]];
                var colorsTwo:Array = [["Sky Blue", "colors2a"], ["Cyan", "colors1b"]];



                function buildAllColors() {
                var spacing:Number = 20;
                for (var i = 0; i < 2; ++i) {
                var name:String = "flipper" + i + "_mc";
                var y:Number = i * spacing;
                _root.m1.attachMovie("flipper", name, i);
                _root.m1[name]._x = 0;
                _root.m1[name]._y = y;
                _root.m1[name].main_text.text = AllColors [0];
                _root.m1[name].menuTwoID = AllColors
                [1];
                _root.m1[name].item_btn.onPress = function () {
                itemClicked (this._parent.menuTwoID);
                for (var i = 0; i < 2; ++i) {
                _root.m1["flipper" + i + "_mc"].flipper_bg._alpha = 50;
                }
                this._parent.flipper_bg._alpha = 100;

                }
                }
                }

                buildAllColors();


                function itemClicked (menuTwoID:String){
                var spacing:Number = 20;
                for (i=0; i<2; i++){
                var y:Number = i * spacing;
                var name:String = "flipper" + i + "_mc";
                _root.m2.attachMovie("flipper", name, i);
                _root.m2[name]._x = 0;
                _root.m2[name]._y = y;
                _root.m2.attachMovie("flipper", name, i);
                _root.m2[name].main_text.text = menuTwoID [1];

                }
                }



                stop();