*.fla
*.swf
StreamInfo.txt
+StreamInfo2.txt
audio
\ No newline at end of file
package {
+
import flash.events.Event;
import flash.events.EventDispatcher;
- public class BaseRegistry extends EventDispatcher implements IRegistry {
+ public class BaseRegistry implements IRegistry {
- private var stage:Object;
- private var head:Object;
- private var lastUpdated:Array;
+ protected var stage:Object;
+ protected var head:Object;
+ protected var lastUpdated:Array;
- public static const REGISTRY_UPDATE = "registry_update";
-
public function BaseRegistry() {
this.stage = {};
this.head = {};
this.head = Util.extend(this.head, this.stage);
this.lastUpdated = Util.toPropertyChains(this.stage);
this.stage = {};
- this.dispatchEvent(new Event(REGISTRY_UPDATE));
}
}
package {
- import flash.events.Event;
- import flash.events.EventDispatcher;
import flash.net.*
+ import flash.events.Event;
+ import flash.events.IOErrorEvent;
- public class ConfigParserRegistry extends BaseRegistry {
+ public class ConfigParserRegistry extends PollableBaseRegistry {
private var request:URLRequest;
private var loader:URLLoader;
private var fileLock:Boolean;
private var loadCallback:Function;
-
public function ConfigParserRegistry(fileName:String) {
+ super(this.parse);
this.fileLock = false;
this.request = new URLRequest(fileName);
this.loader = new URLLoader();
this.loadCallback = this.onLoaded(this);
loader.addEventListener(Event.COMPLETE, this.loadCallback);
+ loader.addEventListener(IOErrorEvent.IO_ERROR, this.ioError);
this.fileLock = true;
this.loader.load(this.request);
} else {
private function releaseLock() {
this.fileLock = false;
}
-
+
+ // Sometimes I think this acesses the file at the same time it is being saved
+ // which causes havock. In that case I just release the lock and clear everything.
+ private function ioError(e:Event) {
+ this.loader.removeEventListener(Event.COMPLETE, this.loadCallback);
+ this.loader.removeEventListener(IOErrorEvent.IO_ERROR, this.ioError);
+ this.releaseLock();
+ }
+
private function onLoaded(configParser:ConfigParserRegistry):Function {
return function(e:Event):void {
//Deal with windows style line endings, and tabs.
configParser.parseVars(lines);
configParser.releaseLock();
configParser.loader.removeEventListener(Event.COMPLETE, configParser.loadCallback);
+ configParser.loader.removeEventListener(IOErrorEvent.IO_ERROR, configParser.ioError);
}
}
--- /dev/null
+package {
+ import flash.events.IEventDispatcher;
+
+ public interface IPollable extends IEventDispatcher {
+
+ function getPollableFunction():Function;
+ function dispatchUpdateEvent():void;
+ function getUpdateEventType():String;
+ function dispatchCycleCompleteEvent():void;
+ function getCycleCompleteEventType():String;
+ }
+
+}
--- /dev/null
+package {
+
+ public interface IPollableRegistry extends IRegistry, IPollable {
+
+ // I Dunno LOL ¯\(°_o)/¯
+
+ }
+
+}
package {
- import flash.events.IEventDispatcher;
-
- public interface IRegistry extends IEventDispatcher
+
+ public interface IRegistry
{
function add(obj:Object):void;
function commit():void;
public class Overlay extends flash.display.MovieClip {
- private var conf:ConfigParserRegistry;
- //private var musicBox:MusicBox;
+ private var registry:Registry;
/*
* After doing some science, 50ms seems to be roughly the time it takes
* for a request to complete and for the locking to not happen.
*/
- private const REFRESH_RATE = 1000;
+ private const REFRESH_RATE = 10;
public function Overlay() {
- this.conf = new ConfigParserRegistry("StreamInfo.txt");
- setInterval(this.conf.parse, REFRESH_RATE);
- this.conf.addEventListener(BaseRegistry.REGISTRY_UPDATE, this.updated);
+ this.registry = new Registry(REFRESH_RATE);
+ var confParser:ConfigParserRegistry = new ConfigParserRegistry("StreamInfo.txt");
+ var confParser2:ConfigParserRegistry = new ConfigParserRegistry("StreamInfo2.txt");
-
- //this.streamInfo = new StreamInfo("Cam", REFRESH_RATE);
- //this.musicBox = new MusicBox(this.streamInfo);
-
- //this.streamInfo.addEventListener(StreamInfo.INFO_UPDATE, this.streamInfoUpdated);
+ this.registry.addSubRegistry(confParser);
+ this.registry.addSubRegistry(confParser2);
+
+ //this.registry.addEventListener(confParser.getUpdateEventType(), this.updated);
}
private function updated(e:Event) {
- var cam:Object = this.conf.get('Cam');
- trace(cam.MusicBoxBase);
+ trace("updated");
+ //var cam:Object = this.conf.get('Cam');
+ //trace(cam.MusicBoxBase);
}
-
}
-
}
--- /dev/null
+package {
+
+ import flash.events.Event;
+
+ public class PollEvent extends Event {
+
+ public var pollTarget:Object;
+
+ public function PollEvent(type:String, target:Object) {
+ super(type);
+ this.pollTarget = target;
+ }
+ }
+
+}
--- /dev/null
+package {
+ import flash.events.Event;
+ import flash.events.EventDispatcher;
+
+ public class PollableBaseRegistry extends BaseRegistry implements IPollableRegistry {
+
+ private var dispatcher:EventDispatcher;
+ private var pollFunction:Function;
+
+ private static const REGISTRY_UPDATE = "registry_update";
+ private static const CYCLE_COMPLETE = "cycle_complete";
+
+ public function PollableBaseRegistry(pollFunction:Function = null) {
+ this.dispatcher = new EventDispatcher();
+ this.pollFunction = pollFunction;
+ }
+
+ public function getPollableFunction():Function {
+ return this.pollFunction;
+ }
+
+ public override function commit():void {
+ if(!Util.objectIsEmpty(this.stage)) {
+ this.head = Util.extend(this.head, this.stage);
+ this.lastUpdated = Util.toPropertyChains(this.stage);
+ this.stage = {};
+ this.dispatchUpdateEvent();
+ }
+
+ this.dispatchCycleCompleteEvent();
+ }
+
+ public function dispatchUpdateEvent():void {
+ this.dispatchEvent(new PollEvent(this.getUpdateEventType(), this));
+ }
+
+ public function getUpdateEventType():String {
+ return REGISTRY_UPDATE;
+ }
+
+ public function dispatchCycleCompleteEvent():void {
+ this.dispatchEvent(new PollEvent(this.getCycleCompleteEventType(), this));
+ }
+
+ public function getCycleCompleteEventType():String {
+ return CYCLE_COMPLETE;
+ }
+
+ //Wrappers around EventDispatcher
+ public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void {
+ this.dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
+ }
+ public function dispatchEvent(event:Event):Boolean {
+ return this.dispatcher.dispatchEvent(event);
+ }
+ public function hasEventListener(type:String):Boolean {
+ return this.dispatcher.hasEventListener(type);
+ }
+ public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void {
+ this.dispatcher.removeEventListener(type, listener, useCapture);
+ }
+ public function willTrigger(type:String):Boolean {
+ return this.dispatcher.willTrigger(type);
+ }
+
+ }
+
+}
package {
+ import flash.events.Event;
+ import flash.utils.*;
+ import flash.text.engine.EastAsianJustifier;
- import flash.events.EventDispatcher;
- import flash.sampler.Sample;
-
- public class Registry implements IRegistry extends EventDispatcher {
-
- private var stage:Object;
- private var head:Object;
- private var lastUpdated:Array;
-
- public static const REGISTRY_UPDATE = "registry_update";
-
- public function Registry() {
- this.stage = {};
- this.head = {};
- }
+ public class Registry extends PollableBaseRegistry {
+
+ private var subRegistries:Array;
+ private var numRegistriesPolled:int;
+ private var refreshRate:int;
- public function add(obj:Object):void {
- this.stage = Util.merge(this.stage, obj);
+ public function Registry(refreshRate:int) {
+ this.subRegistries = [];
+ this.numRegistriesPolled = 0;
+ this.refreshRate = refreshRate;
+
+ setInterval(this.poll, this.refreshRate);
}
- public function commit():void {
- this.head = Util.extend(this.head, this.stage);
- this.lastUpdated = Util.toPropertyChains(this.stage);
- this.stage = {};
+ public function addSubRegistry(subRegistry:IPollableRegistry, registryCallback:Function = null) {
+ this.subRegistries.push(subRegistry);
+ subRegistry.addEventListener(subRegistry.getUpdateEventType(), this.updated);
+ subRegistry.addEventListener(subRegistry..getCycleCompleteEventType(), this.cycleComplete);
}
- public function get(propChain:String):* {
- return Util.resolvePropertyChain(propChain, this.head);
+ private function poll() {
+ // This acts as a lock. After all the registries are polled, it resets to 0
+ // so we know it's safe to poll again.
+ if(this.numRegistriesPolled === 0) {
+ for each(var subRegistry:Object in this.subRegistries) {
+ this.numRegistriesPolled++;
+ var fn:Function = subRegistry.getPollableFunction();
+ fn();
+ }
+ }
}
- public function getLastUpdated():Array {
- return this.lastUpdated;
+ private function updated(e:PollEvent) {
+ trace(e.pollTarget.getLastUpdated());
}
- public function get(member:String) {
- return Util.resolvePropertyChain(member, this.head);
+ private function cycleComplete(e:PollEvent) {
+ if(this.numRegistriesPolled == this.subRegistries.length) {
+ //trace("polling complete");
+ this.numRegistriesPolled = 0;
+ }
+
}
}