Friday, May 6, 2011

Creating an AIR application with an SQLite database: Part 1

Today we will start creating a contact book application using AIR and SQLite database.

In the previous tutorials we've learned about SQL and now have some basic knowledge about using SQLite databases in AIR applications. Now it is time for practice, and we are going to create a working contacts book application, where all items are stored in a SQLite database.

In this tutorial, we will just set everything up to be ready to code.

We'll need to create a List component, three buttons and 3 text fields. If you are using Flash IDE, you can simply drag the components from the component window to the stage and create textfields using the text tool.

We need to have one List component (for displaying all the items in the database) called itemList. We'll need one button for creating new items, called b_new. We'll 3 text fields with labels next to them - First name, Last name, Phone. The instance names of the text fields should be t_fname, t_lname, t_phone. Make sure that they are input fields (that can be edited by the user). Of course, it's not too likely to ever find a need in a databse like this - a database that stores first and last names of a person and their phone number and nothing else, but this is just for this tutorial series purpose, and can be easily changed to suit any other needs later.

Next to the text fields you need to have 2 more buttons - Save this item and Delete this item. We will later make it so that you need to have an item selected in the List for these two buttons to become available, and you need to edit at least one symbol in any of the text fields for the Save this item button to be available. If the user, for example, decides to edit the phone number of one person - the Save button becomes available. If the user clicks it - the item is updated in the database. If the user doesn't save the changes and then selects another user - he didnt update the item in the database so his changes weren't saved.

Here's a picture explaining how everything should be put, with the objects' instance names in red next to the objects:

As I said before, you will probably never need to just store peoples' names and phone numbers, but the purpose of this tutorial series is to learn how to work with SQL databases in AIR and have some experience in that. If you are just here for the code to create a SQLite database powered application, such as contact book, todo list, mp3 player with playlists, etc. - you can read this tutorial to fully understand the mechanics, and then you'll need to modify a few things here and there to suit your needs.

We have everything set up now. We'll start coding in the next part!

Thanks for reading!


Creating an AIR application with an SQLite database: Part 2
Creating an AIR application with an SQLite database: Part 3
Creating an AIR application with an SQLite database: Part 4


Anibus said...

I am using flash Builder 4.5 and
import; gives me an error is there a work around? I really like your routine and can't wait to see it work...thanks

Kirill Poletaev said...

I am writing a tutorial series about making the same type of application but in Flex, stay tuned - it will come out somewhere in the end of September.

Alphaleo said...

Hi really useful tutorial, quick question is there any way I can specify the path of the db file created?

I want to try put the file on a server and try connect to it online, read and write data etc. Any help would be greatly appreciated.:)


Byron Wright

Vivek said...

can i use this all in flash cs5?

Ahlam Mallak said...

hi I'm very new in ActionScript but I'm developing an android application using adobe flash professional cs5.5, my app needs database, so this tutorial very important to me as a starting step in the world of sqlite :P, anyway I did the whole tutorial step by step but it didn't seem to work, it always generate the same error:
scene1,Layer 'code' , frame 1, line 19
1120:Access of undefined property SQLMode

so what should I do????? I renamed the whole objects correctly as it's in the tutorial, I also installed the sqliteODBC driver just in case that the database is not verified by windows7, I did every possible solution, but the error won't disappear please help me to start using SQlite in flash cs5.5 without errors, because it very important to me to complete my project, any ideas please tell me

Kirill Poletaev said...


Try importing the SQLMode class in the beginning of your code and tell me if it worked:


Ahlam Mallak said...

hi again OPSss it was fast I've just solved my own problem you've forgot to import the following:
import flash.errors.SQLError;
so because of this it didn't work at first
thnx anyway :) it was really an amazing tutorial

Ahlam Mallak said...

hhhhh thanks dude

Headhunter said...

hi, nice tutorial series.. I am facing a weird issue. When i try to import any of those. Flash Pro CS6 cant find it. like when i write "import flash.", in the hints window, there is not "data" and in the "events", there are no SQL events...a response would be greatly appreciated!


masai said...

Hi, every time I update my app the SQLite database results as empty!! How is it possible??

Bobsmo said...

how would I retrieve the data ? Say I want to recall the data in #1 item. with a timeline event - or even on a different button then what is in the list ?

Post a Comment