JavaScript Titanium App int assignment
I'm working in JavaScript with Titanium for mobile app development. I'm having a problem down in the for loop with the bn int count. button[bn].setTitle('*') will always be 5 on all buttons created in the event handler, or if I uncomment //bn = 0;, which is outside of the for loop, it will update all buttons to be value zero.

In my mind, it should be assigning the value to each button,event handler, etc at the time of creation and not going back and changing it as it moves the count forward. What am I missing here or need to do different?

    /**
     * create a view object to hold the buttons
     * and add the buttons into the view
     */
    function createRatingButtons(numButtons,BarTitle,topspace) {
        // set vars
        var bn=0;
        var left = 5;
        var top =   5;
        /*
         * create a view for the buttons
         */
        var ratingView = Titanium.UI.createView({
            height:     100,
            color:      'white',
            top:        topspace,
        });
     
        /*
         * create a label to put into the view
         */
        var ratingLabel = Titanium.UI.createLabel({
                    text:                           BarTitle,
                    color:                      '#fff',
                    backgroundColor:    'transparent',
                    textAlign:              'left',
                    height:                     'auto',
                    width:                      'auto',
                    top:                            0,
                    left:                           left,       
        })
        ratingView.add(ratingLabel);
        /*
         * do the for loop and add
         * the buttons to the view
         */
            var button = [];
        for(bn==0;bn<numButtons;bn++) {
                        button[bn] = Titanium.UI.createButton({
                    title:              bn,
                    width:              50,
                    height:             50,
                    color:              "black",
                    // backgroundColor:    "blue",
                    left:               left,
                    top:                                top+ratingLabel.getHeight(),
                });
                /*
                 * Add event handler for this button
                 */
                button[bn].addEventListener('click', function(e)
                            {
                                Ti.API.info("Rating Button Click #: " + bn);
                                /*
                                 * Update buttons below this count for this object
                                 * to have colored stars, and all starts after this
                                 * to be uncolored.
                                 */
                                button[bn].setTitle('*')
                            });
     
     
                ratingView.add(button[bn]);
                left = left + 50 + 5;
        }
        //bn = 0;
     
      // return the entire block for this view  
        return ratingView;
    }
JavaScript Titanium App int assignment
===

I'm working in JavaScript with Titanium for mobile app development. I'm having a problem down in the for loop with the bn int count. button[bn].setTitle('*') will always be 5 on all buttons created in the event handler, or if I uncomment //bn = 0;, which is outside of the for loop, it will update all buttons to be value zero.

In my mind, it should be assigning the value to each button,event handler, etc at the time of creation and not going back and changing it as it moves the count forward. What am I missing here or need to do different?

    /**
     * create a view object to hold the buttons
     * and add the buttons into the view
     */
    function createRatingButtons(numButtons,BarTitle,topspace) {
        // set vars
        var bn=0;
        var left = 5;
        var top =   5;
        /*
         * create a view for the buttons
         */
        var ratingView = Titanium.UI.createView({
            height:     100,
            color:      'white',
            top:        topspace,
        });
     
        /*
         * create a label to put into the view
         */
        var ratingLabel = Titanium.UI.createLabel({
                    text:                           BarTitle,
                    color:                      '#fff',
                    backgroundColor:    'transparent',
                    textAlign:              'left',
                    height:                     'auto',
                    width:                      'auto',
                    top:                            0,
                    left:                           left,       
        })
        ratingView.add(ratingLabel);
        /*
         * do the for loop and add
         * the buttons to the view
         */
            var button = [];
        for(bn==0;bn<numButtons;bn++) {
                        button[bn] = Titanium.UI.createButton({
                    title:              bn,
                    width:              50,
                    height:             50,
                    color:              "black",
                    // backgroundColor:    "blue",
                    left:               left,
                    top:                                top+ratingLabel.getHeight(),
                });
                /*
                 * Add event handler for this button
                 */
                button[bn].addEventListener('click', function(e)
                            {
                                Ti.API.info("Rating Button Click #: " + bn);
                                /*
                                 * Update buttons below this count for this object
                                 * to have colored stars, and all starts after this
                                 * to be uncolored.
                                 */
                                button[bn].setTitle('*')
                            });
     
     
                ratingView.add(button[bn]);
                left = left + 50 + 5;
        }
        //bn = 0;
     
      // return the entire block for this view  
        return ratingView;
    }