Skip to content

Instantly share code, notes, and snippets.

@robertpenner
Created November 26, 2009 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertpenner/243608 to your computer and use it in GitHub Desktop.
Save robertpenner/243608 to your computer and use it in GitHub Desktop.
setInterval internals decompiled from Flash 10 playerglobal.swc
//Created by Action Script Viewer - http://www.buraks.com/asv
package flash.utils {
public function setTimeout(closure:Function, delay:Number, ... _args):uint{
return (new SetIntervalTimer(closure, delay, false, _args).id);
}
}//package flash.utils
import flash.events.*;
package flash.utils {
public function setInterval(closure:Function, delay:Number, ... _args):uint{
return (new SetIntervalTimer(closure, delay, true, _args).id);
}
}//package flash.utils
package flash.utils {
public function clearTimeout(id:uint):void{
SetIntervalTimer.clearInterval(id);
}
}//package flash.utils
package flash.utils {
final class SetIntervalTimer extends Timer {
private var closure:Function;
private var rest:Array;
var id:uint;
private static var intervals:Array = [];
function SetIntervalTimer(closure:Function, delay:Number, repeats:Boolean, rest:Array){
super(delay, (repeats) ? 0 : 1);
this.closure = closure;
this.rest = rest;
addEventListener(TimerEvent.TIMER, this.onTimer);
start();
this.id = (intervals.length + 1);
intervals.push(this);
}
private function onTimer(event:Event):void{
this.closure.apply(null, this.rest);
if (repeatCount == 1){
this.clearArrayEntry();
};
}
function clearArrayEntry():void{
var i:int;
while (i < intervals.length) {
if (intervals[i] == this){
intervals[i] = 0;
break;
};
i++;
};
}
static function clearInterval(id:uint):void{
id--;
if ((intervals[id] is SetIntervalTimer)){
intervals[id].stop();
delete intervals[id];
};
}
}
}//package flash.utils
package flash.utils {
public function clearInterval(id:uint):void{
SetIntervalTimer.clearInterval(id);
}
}//package flash.utils
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment