Initial commit
authorCameron Ball <c.ball1729@gmail.com>
Thu, 16 Apr 2015 09:47:57 +0000 (17:47 +0800)
committerCameron Ball <c.ball1729@gmail.com>
Thu, 16 Apr 2015 09:47:57 +0000 (17:47 +0800)
.gitignore [new file with mode: 0644]
Overlay.as [new file with mode: 0644]
StreamInfo.as [new file with mode: 0644]
StreamInfo.txt [new file with mode: 0644]
test.html [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..ea39644
--- /dev/null
@@ -0,0 +1,2 @@
+*.fla
+*.swf
\ No newline at end of file
diff --git a/Overlay.as b/Overlay.as
new file mode 100644 (file)
index 0000000..3e42a1f
--- /dev/null
@@ -0,0 +1,25 @@
+package  {
+       import flash.utils.*;
+       import flash.display.MovieClip;
+
+       public class Overlay extends flash.display.MovieClip {
+
+               /*
+                * 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 = 50;
+
+               public function Overlay() {
+                       var streamInfo:StreamInfo = new StreamInfo();
+                       
+                       setInterval(function() {
+                               streamInfo.parse("Cam", function() {
+                                       test.text = streamInfo.getStreamParameter("a");
+                               });
+                       },this.REFRESH_RATE);
+               }
+
+       }
+       
+}
diff --git a/StreamInfo.as b/StreamInfo.as
new file mode 100644 (file)
index 0000000..2b61fe3
--- /dev/null
@@ -0,0 +1,73 @@
+package  {
+       import flash.events.Event;
+       import flash.net.*
+       
+       public class StreamInfo {
+               private var request:URLRequest;
+               private var loader:URLLoader;
+               private var streamInfo = {};
+               private var fileLock = false;
+               private var callback:Function;
+
+               public function StreamInfo() {
+                       this.request = new URLRequest("file:///Z:/Overlay/StreamInfo.txt");
+                       this.loader = new URLLoader();
+               }
+               
+               public function parse(section:String, callback:Function) {
+                       if(!this.fileLock) {
+                               this.callback = callback;
+                               var loadCallback:Function = this.onLoaded(section, this);
+                               
+                               loader.addEventListener(Event.COMPLETE, loadCallback);
+                               this.fileLock = true;
+                               this.loader.load(this.request);
+                               loader.removeEventListener(Event.COMPLETE, callback);
+                       } else {
+                               trace("Lock active, not doing anything.");
+                       }
+               }
+               
+               public function getStreamParameter(name:String) {
+                       return this.streamInfo[name];
+               }
+               
+               private function releaseLock() {
+                       this.fileLock = false;
+               }
+                               
+               private function onLoaded(section:String, streamInfo:StreamInfo):Function {             
+                       return function(e:Event):void {
+                               //Deal with windows style line endings, and tabs.
+                               var lines = streamInfo.loader.data.replace(/(\t|\r)/gi, "").split("\n");
+                               var sectionLines:Array = streamInfo.extractSection(lines, section);
+                               streamInfo.parseVars(sectionLines);
+                               streamInfo.callback();
+                               streamInfo.releaseLock();
+                       }
+               }
+               
+               private function extractSection(lines:Array, section:String) {
+                       var sectionLines:Array = new Array();
+                       var foundFirstLineOfSection:Boolean = false;
+                       for each(var line in lines) {
+                               foundFirstLineOfSection = !foundFirstLineOfSection ? line.indexOf("[" + section + "]") >= 0 : !line.match(/\[\w+\]/);
+                               
+                               if(foundFirstLineOfSection) {
+                                       sectionLines.push(line);
+                               }
+                       }
+                       
+                       return sectionLines;
+               }
+               
+               private function parseVars(lines:Array) {
+                       for each(var line in lines) {
+                               var keyValue = line.split("=", 2);
+                               if(keyValue.length == 2) {
+                                       this.streamInfo[keyValue[0]] = keyValue[1];
+                               }
+                       }
+               }
+       }
+}
diff --git a/StreamInfo.txt b/StreamInfo.txt
new file mode 100644 (file)
index 0000000..c1aeb2f
--- /dev/null
@@ -0,0 +1,7 @@
+[Leeroy]
+Fang=It
+Yea=Boi
+
+[Cam]
+a=memesss
+c=d
\ No newline at end of file
diff --git a/test.html b/test.html
new file mode 100644 (file)
index 0000000..b9791c3
--- /dev/null
+++ b/test.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+       <head>
+               <title>Overlay</title>
+               <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+               <style type="text/css" media="screen">
+               html, body { height:100%; background-color: #ffffff;}
+               body { margin:0; padding:0; overflow:hidden; }
+               #flashContent { width:100%; height:100%; }
+               </style>
+       </head>
+       <body>
+               <div id="flashContent">
+                       <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" id="overlay" align="middle">
+                               <param name="movie" value="overlay.swf" />
+                               <param name="quality" value="high" />
+                               <param name="bgcolor" value="#ffffff" />
+                               <param name="play" value="true" />
+                               <param name="loop" value="true" />
+                               <param name="wmode" value="window" />
+                               <param name="scale" value="showall" />
+                               <param name="menu" value="true" />
+                               <param name="devicefont" value="false" />
+                               <param name="salign" value="" />
+                               <param name="allowScriptAccess" value="sameDomain" />
+                               <!--[if !IE]>-->
+                               <object type="application/x-shockwave-flash" data="overlay.swf" width="550" height="400">
+                                       <param name="movie" value="overlay.swf" />
+                                       <param name="quality" value="high" />
+                                       <param name="bgcolor" value="#ffffff" />
+                                       <param name="play" value="true" />
+                                       <param name="loop" value="true" />
+                                       <param name="wmode" value="window" />
+                                       <param name="scale" value="showall" />
+                                       <param name="menu" value="true" />
+                                       <param name="devicefont" value="false" />
+                                       <param name="salign" value="" />
+                                       <param name="allowScriptAccess" value="sameDomain" />
+                               <!--<![endif]-->
+                                       <a href="http://www.adobe.com/go/getflash">
+                                               <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
+                                       </a>
+                               <!--[if !IE]>-->
+                               </object>
+                               <!--<![endif]-->
+                       </object>
+               </div>
+       </body>
+</html>