· 8 years ago · Apr 16, 2018, 03:32 AM
1package
2{
3 import adobe.utils.ProductManager;
4 import flash.display.Sprite;
5 import flash.data.*;
6 import flash.events.Event;
7 import flash.events.SQLEvent;
8 import flash.filesystem.File;
9 import flash.net.URLLoader;
10 import flash.net.URLRequest;
11 import flash.xml.XMLNode;
12 /**
13 * ...
14 * @author Sina
15 */
16 public class Main extends Sprite
17 {
18
19 private var sqlConn:SQLConnection;
20 private var sqlStatement:SQLStatement;
21 private var xml:XML;
22 private var myLoader:URLLoader;
23
24 public function Main():void
25 {
26 //Creating the DB
27 var dbFile:File = File.applicationStorageDirectory.resolvePath("C:\\Dictionary.db");
28
29 //Creating the SQL Connection
30 sqlConn = new SQLConnection();
31
32 //Creating the SQL Statement variable and connection
33 sqlStatement = new SQLStatement();
34
35 //Opening the connection to the File
36 sqlConn.open(dbFile);
37
38 //Referecing the Connection
39 sqlStatement.sqlConnection = sqlConn;
40
41 //Giving the Statement
42 sqlStatement.text = "CREATE TABLE IF NOT EXISTS DICTIONARY(WordID INTEGER PRIMARY KEY AUTOINCREMENT, word TEXT)";
43
44 //Executing the Statement
45 sqlStatement.execute();
46
47 myLoader = new URLLoader();
48 myLoader.load(new URLRequest("C:\\Users\\Avicenna\\Desktop\\Untold Ent\\WordList.xml"));
49 myLoader.addEventListener(Event.COMPLETE, processXML);
50
51 //sqlConn.close();
52
53 }
54
55 private function processXML(e:Event):void
56 {
57 xml = new XML(e.target.data);
58 var i:int;
59 var j:int;
60 var words:String;
61 var aWords:Array;
62
63 //aWords = [];
64
65 for (i = 1; i <= xml.wordlist[0].words.length(); i++) {
66
67 words = xml.wordlist[0].words[i-1];
68 aWords = words.split(",");
69 //trace (words);
70
71 for (j = 0; j <= aWords.length -1; j++) {
72 //trace (aWords[j]);
73
74 sqlStatement.text = "INSERT INTO Dictionary (word) VALUES ('" + aWords[j] + "')";
75 sqlStatement.execute();
76 }
77
78 }
79
80
81 }
82
83
84
85
86
87 }
88
89}