Jelou...
una tonter�a que tengo en pantalla, por si a alguien
le sirve para algo. El c�digo est� comentado (de forma incluso un poco
hartible :) y creo que est� claro como se usa. Si alguien
necesita m�s explicaciones, que pida por esa boquita :) Nota: la clase est� en un NameSpace que uso para mis
movidas (com.bomberstudios.*) pero vereis que en este
fichero no se crea. Se deja como un ejercicio para el
estudiante... :)Salu2
a!e
--[ "Timer.as" ] ------------------------------------------------------- /* Timer Class
[ DESCRIPTION ]
A Timer object that triggers an event every
defined time period. [ HISTORY ]
v1.0 | 14 Nov 2003 Initial Release
v1.1 | 14 Nov 2003 Bugfixes [ EVENTS ]
onTick(tickNumber);
Called every <interval> time. Sends the current
step (tick) as a parameter, should it be useful
for anything (i.e: stopping the timer after a
certain number of steps) onStop();
Called when the timer is stopped [ PUBLIC METHODS ]
stop();
Stops the timer [ NOTES ]
Timer is based on setInterval, thus its accuracy is
nothing to write home about. Take care when you need
precision (i.e: pixel-perfect movement) [ USAGE ]
Scenario: you want to move a clip using code. In this
sample, we'll move the clip 'foo_mc' to the right for
about 20 seconds, and make it transparent when it stops. <code>
fooTimer = new com.bomberstudios.timer(1000);
fooTimer.onTick = function(tick){
if(tick==20){
this.stop();
} else {
_root.foo_mc._x++;
}
}
fooTimer.onStop = function(){
_root.foo_mc._alpha = 50;
}
</code>
*/
com.bomberstudios.timer = function(interval){
this.$interval = interval;
this.init();
}
com.bomberstudios.timer.prototype.stop = function(){
clearInterval(this.intervalID);
this.onStop();
}
com.bomberstudios.timer.prototype.tick = function(){
this.onTick(this.ticks++);
}
com.bomberstudios.timer.prototype.init = function(){
this.ticks = 0;
this.intervalID = setInterval(this,"tick",this.$interval);
}
;
-------------------------------------------------------<!------------------------------- Lista ASNativos: subscripciones/desubscripciones http://www.sidedev.net/asnativos -------------------------------->
