8 Replies Latest reply on Dec 14, 2009 1:17 PM by Pietro Estrada

    Array assign Buttons actions

    Pietro Estrada

      //AS BEGINS

      var productList:Array = Array("diabeoff", "cholestoff", "inulina", "colageno", "power", "castoff", "dieta", "miel", "extrapower");

       

      var numberOfProducts:Number = productList.length;

       

      function enableButtons(productList:Array, numberOfProducts:Number):Void {

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

                productList[i] = "."+productList[i];

                pressedButton = this.productos+productList[i];

                pressedButton.onPress = function():Void  {

                     trace(pressedButton);

                };

           }

      }

       

      enableButtons(productList,numberOfProducts);

      //AS ENDS

       

       

       

      Anyone can sayme why this is not working?

       

      the actions are not assigning to the buttons

        • 1. Re: Array assign Buttons actions
          kglad Adobe Community Professional & MVP

          your array elements are strings.  use array notation to convert to objects.  so, if those corresponding objects are children of this.productos, use:

           

          Pietro Estrada wrote:

           

          //AS BEGINS

          var productList:Array = Array("diabeoff", "cholestoff", "inulina", "colageno", "power", "castoff", "dieta", "miel", "extrapower");

           

          var numberOfProducts:Number = productList.length;

           

          function enableButtons(productList:Array, numberOfProducts:Number):Void {

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

                    productList[i] = "."+productList[i];

                    pressedButton = this.productos[productList[i]];

                    pressedButton.onPress = function():Void  {

                         trace(pressedButton);

                    };

               }

          }

           

          enableButtons(productList,numberOfProducts);

          //AS ENDS

           

           

           

          1 person found this helpful
          • 2. Re: Array assign Buttons actions
            Ned Murphy Adobe Community Professional & MVP

            I suspect the problem lies in whatever you are trying to do between these lines...

             

                      productList[i] = "."+productList[i];

                      pressedButton = this.productos+productList[i];

             

            What are the buttons' names and what is "this.productos"

            • 3. Re: Array assign Buttons actions
              Pietro Estrada Level 1

              Products is a Movie on Canvans with that instance name...

               

              the name of the buttons are... the names inside the array =)

               

              objets.JPG

              • 4. Re: Array assign Buttons actions
                Pietro Estrada Level 1

                how can I use array notation?

                • 5. Re: Array assign Buttons actions
                  Ned Murphy Adobe Community Professional & MVP

                  Based on what you just described, kGlad's solution should be what you need.

                  • 6. Re: Array assign Buttons actions
                    Pietro Estrada Level 1

                    yes but how I use Array notation?? how I change the sintaxys?

                     

                    =S

                     

                    tansk for the help I'm reading but I dont find about AS, only AJAX, PHP, JAVA

                    • 7. Re: Array assign Buttons actions
                      Ned Murphy Adobe Community Professional & MVP

                      He edited your code for that already...  The following line uses the array syntax...

                       

                      pressedButton = this.productos[productList[i]];

                       

                       

                      The basics of this syntax in that a String value is treated as an instance name when you include it in the brackets as shown...

                       

                      this["some_object_name_as_a_String"]

                       

                      this.productos["buttonname"];

                       

                      etc...

                       

                      The array syntax is a very useful tool to get into your toolbox.

                      • 8. Re: Array assign Buttons actions
                        Pietro Estrada Level 1

                        FINAL PRODUCT

                         

                        //AS BEGINS

                        var productList:Array = Array("diabeoff", "cholestoff", "inulina", "colageno", "power", "castoff", "dieta", "miel", "extrapower");

                         

                        var numberOfProducts:Number = productList.length;

                         

                        function enableButtons(productList:Array, numberOfProducts:Number):Void {

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

                                  pressedButton = this.productos[productList[i]];

                                  pressedButton.onPress = function():Void  {

                                       trace(pressedButton);

                                  };

                             }

                        }

                         

                        enableButtons(productList,numberOfProducts);

                        //AS ENDS