Solved

Flex/Air and SQLite

Posted on 2009-05-14
3
575 Views
Last Modified: 2012-05-07
Could someone show me a very simple example of using Flex/Air with something other than a datagrid?  I'm trying to get a handle on using sqlite and i'd like to have something like a form or a few textinput components that you can input text into, save that data (to sqlite) and then when you reopen the app later, the data is there.
0
Comment
Question by:moglie
  • 2
3 Comments
 
LVL 5

Expert Comment

by:Fuzzy_Logic_
ID: 24392138
0
 
LVL 5

Accepted Solution

by:
Fuzzy_Logic_ earned 500 total points
ID: 24392153
And a crude example I've knocked up stripped down to the bare basics for creating, inserting and selecting:


<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()">
        
        <mx:Script>
                <![CDATA[
                        import mx.collections.ArrayCollection;
                        
                        private var sqlConn:SQLConnection;
                        private var sqlFile:File;
                        
                        private function init():void
                        {
                                sqlFile = File.applicationStorageDirectory.resolvePath("emps.db");
                                sqlConn = new SQLConnection();
                                sqlConn.open(sqlFile, SQLMode.CREATE);
                                
                                var sql:SQLStatement = new SQLStatement();
                                sql.sqlConnection = sqlConn;
                                sql.text = "CREATE TABLE IF NOT EXISTS emps(" + 
                                                "empID INTEGER PRIMARY KEY AUTOINCREMENT, " + 
                                                "eName TEXT, " + 
                                                "age TEXT)";
 
                                 sql.execute();
                                 var result:SQLResult = sql.getResult();
                                 trace("emp table created");
                        }
                        
                        private function saveEmp():void
                        {
                                var sql:SQLStatement = new SQLStatement();
                                sql.sqlConnection = sqlConn;
                                sql.text = 
                                "INSERT INTO emps (" + 
                                "eName, age )" + 
                                "VALUES ('" + 
                                this.eName.text + "', '" + this.age.text + "')";
 
                                sql.execute();
                                var result:SQLResult = sql.getResult();
                                trace("emp saved");
                        }
                        
                        private function getEmp():void
                        {
                        
                                var sql:SQLStatement = new SQLStatement();
                                sql.sqlConnection = sqlConn;
                                sql.text = "SELECT * FROM emps WHERE empID = " + this.numID.value;
                                sql.execute();
                                var result:SQLResult = sql.getResult();
                                
                                var empsAC:ArrayCollection = new ArrayCollection(result.data);
 
                                this.empID.text = empsAC[0].empID;
                                this.eName.text = empsAC[0].eName;
                                this.age.text = empsAC[0].age;
                                
                        }
                        
                ]]>
        </mx:Script>
        
        
        <mx:Tile width="120">
            
        
        <mx:Button label="Save" click="saveEmp()"/>
        <mx:Button label="Get Employee" click="getEmp()"/> <mx:NumericStepper id = "numID" />
        <mx:Label text = "empID" />
        <mx:TextArea id="empID" width = "50" height = "20" editable="false"/>
        <mx:Label text = "eName" />
        <mx:TextArea id="eName" width = "100" height = "20" />
        <mx:Label text = "age" />
        <mx:TextArea id = "age" width = "50" height = "20" />
        
        </mx:Tile>
</mx:WindowedApplication>

Open in new window

0
 

Author Comment

by:moglie
ID: 24396264
Thanks, that's what I needed to get me going in the right direction.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
flex simple crossdomain problem 1 842
CheckBox inside itemRenderer issue 13 590
How to export vector graphics from Actionscript 3.0 SWF? 4 1,190
Indesign Data Merge 1 191
First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now