var testVariable = 0; but.onPress = function() { this.onEnterFrame = function() { if(testVariable<9){ testVariable++; test.text = testVariable; } } } but.onRelease = function(){ delete this.onEnterFrame; }