5 Replies Latest reply on Sep 5, 2009 1:49 PM by kglad

    For Loop help

    Spacer98 Level 1

      Hello! I have the following code for 10 mcs, (product1,product2, etc) Could someone help me to make it loop? I made some tests to make it loop but I dont know exactly how, only the start. Thanks!

       

      _root.menu.product1.onRollOver = function() {
      if (scale==100 && menuchange==true) {
        viewproduct1(); menuoversfx.start();buttonclick=null;
       
        _root.menu.product1.onPress = function() {
        gotoproduct1();
        };
      }
      };

       

      ---------------

      products=10

       

      for (i=0; i<products; i++) {

       

      ???????????????????

       

      }

        • 1. Re: For Loop help
          kglad Adobe Community Professional & MVP

          use:

          var tl:MovieClip=this;

          for(var i:Number=0;i<products;i++){

          _root.menu["product"+i].ivar=i;

          _root.menu["product"+i].onRollOver = function() {
          if (scale==100 && menuchange==true) {
          tl["viewproduct"+i]();

          menuoversfx.start();

          buttonclick=null;
           
            _root.menu["product"+i].onPress = function() {
          tl["gotoproduct"+this.ivar]();
            };

          }
          }
          };

           


          1 person found this helpful
          • 2. Re: For Loop help
            Spacer98 Level 1

            Thank you I ll have it as a reference for my future loops but for now it works, but works only for last rollover ( _root.menu.product10.onRollOver = function() { )

             

            I thought of something else, would be better if I had a function that would take the number for example:

             

            _root.menu.product1.onRollOver = function() {
            productrollover(1);

            }

            _root.menu.product2.onRollOver = function() {
            productrollover(2);
            }

             

            etc....

             

            maybe would be like this?

             

            function productrollover(product) {

            if (scale==100 && menuchange==true) {
              viewproduct[product](); menuoversfx.start();buttonclick=null;
              _root.menu.product[product].onPress = function() {
              gotoproduct[product]();
              };
            }
            };

            • 3. Re: For Loop help
              kglad Adobe Community Professional & MVP

              if you add a rollover, you must use this.ivar instead of i just like i did in the onRelease() method.

              • 4. Re: For Loop help
                Spacer98 Level 1

                Ok I finally understood from your loop how to put variables into a function

                 

                This works fine for me

                 

                function productrollover(product) {
                if (scale==100 && menuchange==true) {
                  tl["viewproduct"+product]();
                  tl["menuoversfx.start"]();buttonclick=null;
                  };
                  _root.menu["product"+product].onPress = function() {
                  tl["gotoproduct"+product]();
                  };
                };

                 

                Thank you man!

                • 5. Re: For Loop help
                  kglad Adobe Community Professional & MVP

                  you're welcome.