for (i=0; i<8; i++) { this["item"+i].X = i; this["item"+i].onRelease = function() { state.text = "item"+this.X; }; }