2 Replies Latest reply on Oct 2, 2009 10:16 AM by erthy

    How to take data from an Array and put them into variables?

    erthy Level 1

      Hi!

       

      I am trying to write a program, that will test the user for vocabulary and I am a total (flex, air, programming) beginner. I used the example code here: http://shardulbartwal.wordpress.com/2008/04/14/adobe-air-and-sqlite-connectivity/ and changed it accordingly to my needs. The problem is, in the tutorial, the data is retrieved to a DataGrid and I would like to put them into variables. However, if I ask it to tell me the contents of the Array (line 43) it says [Object, object] and I have no clue what to do.

       

      The code of the original is included in the link, my (changed) code is here:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()"  layout="absolute"> 
         <mx:Script> 
            <![CDATA[   
             import mx.controls.Alert;
            import mx.collections.ArrayCollection;
            import flash.data.*;
           
            private var ob:Array=new Array();
            public var mysqlConnection:SQLConnection;
            public var _createProdct:SQLStatement;
            public var _insertProduct:SQLStatement;
            public var _selectProduct:SQLStatement;
       
            private const _counterProduct:int = 1;
            private var databaseFile:File =
            File.applicationStorageDirectory.resolvePath("slovniky.db");
            private const CREATE_PRODUCT_TABLE:String =
            "CREATE TABLE product (id INTEGER PRIMARY KEY AUTOINCREMENT,jazyk1 TEXT," +
            "jazyk2 TEXT, druh TEXT, pouzito TEXT);"
           
            private var _id:int;
            private var _jazyk1:String;
            private var _jazyk2:String;
            private var _druh:String;
            private var _pouzito:String;
           
            private var INSERT_PRODUCT:String;
            private const SELECT_PRODUCT:String = "SELECT * FROM product";
            private const SELECT_POKUS:String = "SELECT * FROM product WHERE id=2";
           
            private function ask() :void {
            if((databaseFile != null) && (databaseFile.exists))
                        {
                              _selectProduct =new SQLStatement();
                                  mysqlConnection=new SQLConnection();
                                  _selectProduct.sqlConnection = mysqlConnection;
                                  mysqlConnection.open(databaseFile,SQLMode.READ);
                                  _selectProduct.text = SELECT_POKUS;
                                  _selectProduct.execute();
                                  ob=_selectProduct.getResult().data;
                                  mysqlConnection.close();
                                  Alert.show("This is OB:"+ob);
                                  // dg1.dataProvider=ob;
                        }
                        else
                        {
                              Alert.show("There is no database so please create it First.");
                        }
                 
            }
            
            private function starter() :void {
                    slovickoEn.enabled = true;
                    nazor.enabled = true;
                    odeslat.enabled = true;
                    zrusit.enabled = true;
                    start.enabled = false;
                     ask();
               }
               
               private function kontrola() : void { 
                    if (nazor.text != "") {
                    
                         if (nazor.text == "Pes") {
                         Alert.show("Správně!");     
                         }
                    
                         else {
                         Alert.show("Špatně!! " + "Napsané slovíčko bylo " + nazor.text);      
                         }
                    }
               }
      ]]>   
         </mx:Script>
      <mx:VBox width="400" height="200" 
                     horizontalCenter="0" verticalCenter="0" backgroundColor="#FFFFFF"
                     paddingBottom="20" paddingLeft="20" paddingRight="20" paddingTop="20" 
         > 
            <mx:HBox width="100%" verticalAlign="middle" horizontalAlign="center"> 
               <mx:Label text="Anglicky:"/> 
               <mx:TextInput id="slovickoEn" editable="false" text="Dog" enabled="false"/> 
            </mx:HBox>
            <mx:HBox width="100%" verticalAlign="middle" horizontalAlign="center"> 
               <mx:Label text="Česky:"/> 
               <mx:TextInput id="nazor"  enter="kontrola()" enabled="false"/> 
            </mx:HBox> 
            <mx:HBox width="100%" horizontalAlign="center"> 
               <mx:Spacer width="50" height="10"/> 
               <mx:Button id="odeslat" label="Odeslat" color="#0D8401" click="kontrola()" enabled="false"/> 
               <mx:Button id="zrusit" label="Zrušit" color="#0D8401" enabled="false"/> 
            </mx:HBox>
            <mx:HBox width="100%" horizontalAlign="center"> 
               <mx:Spacer width="50" height="10"/> 
               <mx:Button id="start" label="Start" color="#0D8401" click="starter()" enabled="true"/> 
            </mx:HBox>    
         </mx:VBox>
       </mx:WindowedApplication>
      

      Please tell me, what I am doing wrong, and how to achieve what I want.

      Erthy