<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" viewActivate="view1_viewActivateHandler(event)" title="{data.title}" xmlns:components="components.*">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import spark.events.ViewNavigatorEvent;
import views.SnippetView;
public var sqlConnection:SQLConnection;
protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
{
sqlConnection = new SQLConnection();
sqlConnection.open(File.applicationStorageDirectory.resolvePath("giberish.db"));
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = "CREATE TABLE IF NOT EXISTS giberish (label TEXT)";
stmt.execute();
getAllGiberish();
}
protected function getAllGiberish():void {
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = "SELECT label FROM giberish";
stmt.execute();
l.dataProvider = new ArrayCollection(stmt.getResult().data);
}
protected function button1_clickHandler(event:MouseEvent):void
{
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = "INSERT into giberish values(:giberish)";
stmt.parameters[":giberish"] = g.text;
stmt.execute();
getAllGiberish();
g.text = "";
}
]]>
</fx:Script>
<s:navigationContent>
<s:Button label="Snippet" click="navigator.pushView(views.SnippetView,data)"/>
<s:Button label="Tutorial" click="navigateToURL(new URLRequest(data.tutorial))"/>
</s:navigationContent>
<s:layout>
<s:VerticalLayout gap="10" paddingLeft="10" paddingTop="10"/>
</s:layout>
<s:Label text="Enter some giberish:"/>
<s:TextInput id="g" width="400"/>
<s:Button label="Save Giberish" enabled="{g.text.length != 0}" click="button1_clickHandler(event)"/>
<s:Label text="Saved Giberish:" paddingTop="20"/>
<s:List id="l" width="100%" height="100%"/>
<components:QuestionBlock bottom="40" horizontalCenter="0" questionData="{data}"/>
</s:View>