0 Replies Latest reply on Mar 18, 2011 5:30 PM by Richard Soper

    AIR for Android Local Storage

    Richard Soper

      I'm trying to use the local storage technique shown in Tour De Flex mobile, and as far as I can see the code should be working, but my list only returns [object Object] for each instance submitted to the table. Can anyone help me figure out whats wrong?

       

      <?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" title="New Game Set-up" creationComplete="init();">

      <fx:Declarations>

      <!-- Place non-visual elements (e.g., services, value objects) here -->

      </fx:Declarations>

      <fx:Script>

      <![CDATA[

       

      public function init():void{

      sqlConnection = new SQLConnection();

      sqlConnection.open(File.applicationStorageDirectory.resolvePath("disc.db"));

      var statement:SQLStatement = new SQLStatement();

      statement.sqlConnection = sqlConnection;

      statement.text = "CREATE TABLE IF NOT EXISTS playerData (name TEXT, par TEXT)";

      statement.execute();

      getAllPlayers();

      }

       

      import mx.collections.ArrayCollection;

       

      public var sqlConnection:SQLConnection;

       

      public function getAllPlayers():void{

      var statement:SQLStatement = new SQLStatement();

      statement.sqlConnection = sqlConnection;

      statement.text = "SELECT name FROM playerData";

      statement.execute();

      players.dataProvider = new ArrayCollection(statement.getResult().data);

      }

       

      public function addPlayer():void{

      var statement:SQLStatement = new SQLStatement();

      statement.sqlConnection = sqlConnection;

      statement.parameters[0] = pName.text;

      statement.parameters[1] = pPar.text;

      statement.text = "INSERT INTO playerData (name, par) VALUES(?, ?)";

      statement.execute();

      getAllPlayers();

      }

       

      ]]>

      </fx:Script>

      <fx:Script source="../setup-func.as"/>

      <s:Scroller left="0" right="0" top="0" bottom="0">

      <s:Group>

      <s:Label left="10" top="21" fontSize="60" text="Options"/>

      <s:CheckBox id="score" left="10" top="86" label="Keep Score?" enabled="true"

      selected="true" textDecoration="none" change="keepScore()"/>

      <s:Group id="scoreOpt" left="10" right="10" top="173">

      <s:Group id="form" left="0" right="0">

      <s:TextInput id="pName" left="0" width="50%" verticalCenter="0"/>

      <s:Group right="0" top="0" bottom="0" width="50%">

      <s:Label left="7" text="Par" verticalCenter="0"/>

      <s:TextInput id="pPar" left="55" right="75" top="0" verticalCenter="0"/>

      <s:Button y="0" right="0" width="60" height="75" label="+" click="addPlayer()"/>

      </s:Group>

      </s:Group>

      <s:List id="players" left="0" right="0" top="100" bottom="0"/>

      </s:Group>

      </s:Group>

      </s:Scroller>

      </s:View>