package com.identityMine.filereader { import flash.filesystem.*; import flash.display.MovieClip; // The extention here is to make it so that I can independently test these routines public class FILEREADER extends MovieClip { // Constructor - loads in the input file we are reading public function FILEREADER(){ // Create a file object and let our app know where the file // exists // have we seen the "Begin Surface" command yet? var inSurface : Boolean = false; var inTrace : Boolean = false; var inSpider : Boolean = false; var inMove : Boolean = false; // This is the file we are reading var myFile:File = File.applicationDirectory; myFile = myFile.resolvePath("mySampleFile.txt"); var fileStream : FileStream = new FileStream(); fileStream.open(myFile, FileMode.READ); // Everything inside our file var fileContents : String = fileStream.readUTFBytes(fileStream.bytesAvailable); // Split our entire file based on newlines var splitString = fileContents.split("\n"); // this prints out everything in my fileContents string // trace (splitString); // iterate through each element in the array // each represents a piece of information necessary to construct our // visualization // looping variable var i : int; // splitting variable var split_val : int; // Regular Expression for matching a string of 1 or more digits var re1 = new RegExp("[0-9]+"); // Regular Expression for matching a sequence of alph characters var re2 = new RegExp("[a-z]*[A-Z]*"); var re3 = new RegExp("[//s]*LegAttach"); var SubVals; for (i = 0; i < splitString.length; i++){ // pass over comments, which begin with a "//" if (splitString[i].substr(0,2) == "//"){ continue; } // If we hit the "Begin Surface" command. split_val = "Begin Surface".length; if (splitString[i].substr(0,split_val) == "Begin Surface"){ inSurface = true; // The very next line must be our surface coordinates, // so we can skip it and call our surface generation function // generateSurface(num_1, num_2, num_3, num_4); /// Not Written YET // Advance past our next line i = i + 1; continue; } // If our line starts with integers and we are in the surface description portion of // our code if ((re1.test(splitString[i]) == true) && (inSurface == true)){ // Get all the subValues from here // 1st - number // 2nd - number // 3rd - index will be a unique way of referring to this DNA piece // - should it always be a number? I'll ask Mark how he wants to handle this // 4th - species - probably a string describing it // 1st & 2nd are the only really important ones now, 3rd & 4th can wait. SubVals = splitString[i].split(','); // call our DNA placement method // // generateDNA(SubVals[0], SubVals[1], SubVals[2], SubVals[3]); /// Not Written Yet // continue; } split_val = "End Surface".length; if (splitString[i].substr(0,split_val) == "End Surface"){ inSurface = false; continue; } split_val = "Begin Trace".length; if (splitString[i].substr(0,split_val) == "Begin Trace"){ inTrace = true; continue; } split_val = "Begin Spider".length; if (splitString[i].substr(0,split_val) == "Begin Spider"){ inSpider = true; continue; } split_val = "End Spider".length; if ((splitString[i].substr(0,split_val) == "End Spider") && (inSpider == true)){ inSpider = false; continue; } if ((re2.test(splitString[i]) == true) && (inSpider == true)){ SubVals = splitString[i].split(','); // Make our spider with the different components of this line // generateSpider(SubVals[0], SubVals[1], SubVals[2]); /// Not Written Yet continue; } split_val = "Body Move".length; if (splitString[i].substr(0,split_val) == "Body Move"){ inMove = true; continue; } split_val = "Spider Detach".length; if ((splitString[i].substr(0,split_val) == "Spider Detach") && (inMove == true) && (inTrace == true)){ inMove = false; continue; } split_val = "End Trace".length; if((splitString[i].substr(0, split_val) == "End Trace") && (inTrace == true)) { inTrace = false; continue; } split_val = "LegAttach".length; if((re3.test(splitString[1]) == true) && (inTrace == true) && (inMove == true)){ SubVals = splitString[i].split(','); /// Call spider leg attach method /// legAttach(SubVals[0], SubVals[1], SubVals[2]); /// Not Written Yet continue; } // Trace what we have left to handle trace(splitString[i]); } fileStream.close(); } } }