· 8 years ago · Apr 16, 2018, 04:22 AM
1package
2{
3 //My imports statement for sqlite and xml loaders
4 import flash.data.SQLConnection;
5 import flash.data.SQLStatement;
6 import flash.display.Sprite;
7 import flash.events.Event;
8 import flash.filesystem.File;
9 import flash.net.URLLoader;
10 import flash.net.URLRequest;
11
12 /**
13 * ...
14 * @author Sina Kashanizadeh
15 */
16 public class Main extends Sprite
17 {
18 // variable for SQL connections, statement, xml, xml Loader
19 private var sqlConn:SQLConnection;
20 private var sqlStatement:SQLStatement;
21 private var xml:XML;
22 private var myLoader:URLLoader;
23
24 // Variable to hold the random values that fill the database up with junk data
25 private var randomState:int;
26 private var randomWordColor:int;
27 private var letter:String = "L";
28
29 public function Main():void
30 {
31 //entry point
32
33 //Creating the DB
34 var dbFile:File = File.applicationStorageDirectory.resolvePath("C:\\Dictionary.db");
35
36 //Creating the SQL Connection
37 sqlConn = new SQLConnection();
38
39 //Creating the SQL Statement variable and connection
40 sqlStatement = new SQLStatement();
41
42 //Opening the connection to the File
43 sqlConn.open(dbFile);
44
45 //Referecing the Connection
46 sqlStatement.sqlConnection = sqlConn;
47
48 //Giving the Statement
49 sqlStatement.text = "CREATE TABLE IF NOT EXISTS DICTIONARY(WordID INTEGER PRIMARY KEY AUTOINCREMENT, word TEXT, wordColor TINYINT, wordState TINYINT, wordLength TINYINT, LetterColor NCHAR(8) )";
50
51 //Executing the Statement
52 sqlStatement.execute();
53
54 //Loading the XML File
55 myLoader = new URLLoader();
56 //Path to my xml file
57 myLoader.load(new URLRequest("C:\\Users\\Avicenna\\Desktop\\Untold Ent\\WordList.xml"));
58 //Launching the function that parses
59 myLoader.addEventListener(Event.COMPLETE, processXML);
60 }
61
62 private function processXML(e:Event):void
63 {
64 xml = new XML(e.target.data);
65 var i:int;
66 var j:int;
67 var k :int;
68 var words:String;
69 var aWords:Array;
70 var wordlength:int;
71 var myword:String;
72 var letterColor:String;
73
74 //aWords = [];
75
76 for (i = 1; i <= xml.wordlist[0].words.length(); i++) {
77
78 words = xml.wordlist[0].words[i-1];
79 aWords = words.split(",");
80 //trace (words);
81
82 for (j = 0; j <= aWords.length -1; j++) {
83 //trace (aWords[j]);
84
85 randomState = Math.floor(Math.random() * 4);
86 randomWordColor = Math.floor(Math.random() * 5);
87 myword = aWords[j];
88 wordlength = myword.length;
89
90 letterColor = "";
91
92
93 if (randomWordColor != 4) {
94 for (k = 0; k < wordlength; k++) {
95 letterColor = letterColor + randomWordColor;
96 }
97 }
98 else {
99 for (k = 0; k < wordlength; k++) {
100 letterColor += Math.floor(Math.random()* 4);
101 }
102
103 }
104
105 sqlStatement.text = "INSERT INTO Dictionary (word,wordColor,wordState,wordLength,LetterColor) VALUES ('" + aWords[j] + "'," + randomWordColor + "," +randomState + "," + wordlength + ", '" + letterColor+ "')";
106 sqlStatement.execute();
107
108 test();
109
110 }
111
112
113 }
114
115
116 }
117
118 private function test():void
119 {
120 var aLengths:Array= [3,4,5,6,7,8];
121 var aColors:Array= [1];
122 var firstLetter:String = "A";
123 var aStates:Array = [0,1,2,3];
124
125
126 var strLengths:String="";
127 var strWordColors:String="";
128 var strWordState:String="";
129 var strFirstLetter:String = "";
130 var strWhere:String = "";
131 var strScore:String = "";
132 var OrderBy:String = "";
133
134
135 var i:int;
136 var Param:Boolean = false;
137
138 if (firstLetter != "") {
139 strFirstLetter = "( word like " + "'" + firstLetter + "%') AND ";
140 Param = true;
141
142 }
143
144 trace(strFirstLetter);
145
146 if (aLengths.length > 0) {
147
148 for (i = 0; i <= aLengths.length - 1;i++){
149 strLengths = strLengths + "wordLength = " + aLengths[i] + " OR ";
150 }
151
152 strLengths = strLengths.substr(0, strLengths.length - 3);
153 strLengths = "(" + strLengths + ") AND " ;
154 Param = true;
155 trace(strLengths);
156 }//if
157
158
159
160
161
162 }
163
164
165 }
166
167}