13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with local SQL databases in AIR<br />

private function g<strong>en</strong>erateEncryptionKey(hash:String):ByteArray<br />

{<br />

var result:ByteArray = new ByteArray();<br />

}<br />

for (var i:uint = 0; i < 32; i += 2)<br />

{<br />

var position:uint = i + 17;<br />

var hex:String = hash.substr(position, 2);<br />

var byte:int = parseInt(hex, 16);<br />

result.writeByte(byte);<br />

}<br />

return result;<br />

Strategies for working with SQL databases<br />

Adobe AIR 1.0 and later<br />

There are various ways that an application can access and work with a local SQL database. The application design can<br />

vary in terms of how the application code is organized, the sequ<strong>en</strong>ce and timing of how operations are performed, and<br />

so on. The techniques you choose can have an impact on how easy it is to develop your application. They can affect<br />

how easy it is to modify the application in future updates. They can also affect how well the application performs from<br />

the users’ perspective.<br />

Distributing a pre-populated database<br />

Adobe AIR 1.0 and later<br />

Wh<strong>en</strong> you use an AIR local SQL database in your application, the application expects a database with a certain<br />

structure of tables, columns, and so forth. Some applications also expect certain data to be pre-populated in the<br />

database file. One way to <strong>en</strong>sure that the database has the proper structure is to create the database within the<br />

application code. Wh<strong>en</strong> the application loads it checks for the exist<strong>en</strong>ce of its database file in a particular location. If<br />

the file doesn’t exist, the application executes a set of commands to create the database file, create the database<br />

structure, and populate the tables with the initial data.<br />

The code that creates the database and its tables is frequ<strong>en</strong>tly complex. It is oft<strong>en</strong> only used once in the installed lifetime<br />

of the application, but still adds to the size and complexity of the application. As an alternative to creating the database,<br />

structure, and data programmatically, you can distribute a pre-populated database with your application. To distribute<br />

a predefined database, include the database file in the application’s AIR package.<br />

Like all files that are included in an AIR package, a bundled database file is installed in the application directory (the<br />

directory repres<strong>en</strong>ted by the File.applicationDirectory property). However, files in that directory are read only.<br />

Use the file from the AIR package as a “template” database. The first time a user runs the application, copy the original<br />

database file into the user’s “Pointing to the application storage directory” on page 672 (or another location), and use<br />

that database within the application.<br />

Last updated 6/6/2012<br />

774

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!