Reading a live text file - FileStream

Does anyone have any experience in reading a live text file?

I’m trying to read a text file that’s written with fmCreate or fmShareDenyNone rights.

I’ve written a bit of code (below) that works locally on my computer but when inside the CasparCG Client, it throws a #1014 error (class could not be found). The project has an AIR 2.5 target with ActionScript 3.0.

function update() {

			var file:File = File.documentsDirectory;
			file.resolvePath(path);

			if (file.exists) {
				var fileStream:FileStream = new FileStream();
				fileStream.open(file, FileMode.READ);

				var fileText:String = fileStream.readUTF();

				var rawText:Array = new Array();

				rawText = fileText.split("\n");

				for(var i:int = 0; i < rawText.length; ++i){
					var tempArray:Array = new Array();
				
					//Split Identifier and Data
					tempArray = rawText[i].split("=");
				
					//Place Data into parsedText Array
					var data:String = String(tempArray[1]);
					if (isSubstring){parsedText[i] = data.substr(begin, (data.length - end));}
					else{parsedText[i] = data;}
				}
				
				updateFields();

			}
							
		}

Any help would be greatly appreciated! Thanks so much!

AFAIK you can not use Air classes inside Flash player.

Is there a similar class that is compatible with Flash Player that will allow me to read, parse a live text file?

I’m trying to have it update every 10 milliseconds (for a running clock).

I’ve tried a URLLoader, but I’m getting a #2032 stream error after the text updates for about 5 seconds causing the template to crash.

Thanks for the help!

The problem is, that your template trys to load the textfile sometimes, when it is still beeing writen. That does the crash. By the way: at 50 fps one frame is shown for 20ms, so you do not need to be faster than that. I would update at maximum 10times a second or so. Or only do the whole second from the filöe and let an animation run to make the split seconds to flicker. Nobody will be able to see the difference. - It’s show-business man :slight_smile:

1 Like

:joy::joy:
And don‘t forget, that there is a processing time. So the displayed time is never the official / real time…