Output values for buttons in loop

I have this little loop that creates buttons.
My aim is to change value of variable ‘thevalue’ on everytime button is pressed, first button should give value 0, second 1, third 2 and so on.

for (jo=0; jo<xmlData.firstChild.childNodes.length; jo++) {
            value1= xmlData.firstChild.childNodes[jo].attributes.value;
            _root.attachMovie("button", jo, (1000-jo), {_x:20, _y:20+(jo*20)});
            _root[jo].onPress = function () {
                thevalue=jo;
                _root.actions.Scramble();

            }
}

So help me God 'cos im running slo.