var len:Number = 4; while(len--){ this['lamp'+len].__id=len; this['lamp'+len].onPress=someFunc; } function someFunc(){ trace(this.__id); }