Commiting to continue stuff at home
[swf-overlay.git] / Registry.as
1 package {
2 import flash.events.Event;
3 import flash.utils.*;
4 import flash.text.engine.EastAsianJustifier;
5
6 public class Registry extends PollableBaseRegistry {
7
8 private var subRegistries:Array;
9 private var numRegistriesPolled:int;
10 private var refreshRate:int;
11
12 public function Registry(refreshRate:int) {
13 this.subRegistries = [];
14 this.numRegistriesPolled = 0;
15 this.refreshRate = refreshRate;
16
17 setInterval(this.poll, this.refreshRate);
18 }
19
20 public function addSubRegistry(subRegistry:IPollableRegistry, registryCallback:Function = null) {
21 this.subRegistries.push(subRegistry);
22 subRegistry.addEventListener(subRegistry.getUpdateEventType(), this.updated);
23 subRegistry.addEventListener(subRegistry..getCycleCompleteEventType(), this.cycleComplete);
24 }
25
26 private function poll() {
27 // This acts as a lock. After all the registries are polled, it resets to 0
28 // so we know it's safe to poll again.
29 if(this.numRegistriesPolled === 0) {
30 for each(var subRegistry:Object in this.subRegistries) {
31 this.numRegistriesPolled++;
32 var fn:Function = subRegistry.getPollableFunction();
33 fn();
34 }
35 }
36 }
37
38 private function updated(e:PollEvent) {
39 trace(e.pollTarget.getLastUpdated());
40 }
41
42 private function cycleComplete(e:PollEvent) {
43 if(this.numRegistriesPolled == this.subRegistries.length) {
44 //trace("polling complete");
45 this.numRegistriesPolled = 0;
46 }
47
48 }
49 }
50
51 }