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 />

import flash.data.SQLConnection;<br />

import flash.data.SQLMode;<br />

import flash.ev<strong>en</strong>ts.SQLErrorEv<strong>en</strong>t;<br />

import flash.ev<strong>en</strong>ts.SQLEv<strong>en</strong>t;<br />

import flash.filesystem.File;<br />

var conn:SQLConnection = new SQLConnection();<br />

conn.addEv<strong>en</strong>tList<strong>en</strong>er(SQLEv<strong>en</strong>t.OPEN, op<strong>en</strong>Handler);<br />

conn.addEv<strong>en</strong>tList<strong>en</strong>er(SQLErrorEv<strong>en</strong>t.ERROR, errorHandler);<br />

var dbFile:File = File.applicationStorageDirectory.resolvePath("DBSample.db");<br />

var <strong>en</strong>cryptionKey:ByteArray = new ByteArray();<br />

<strong>en</strong>cryptionKey.writeUTFBytes("Some16ByteString"); // This technique is not secure!<br />

conn.op<strong>en</strong>Async(dbFile, SQLMode.UPDATE, null, false, 1024, <strong>en</strong>cryptionKey);<br />

function op<strong>en</strong>Handler(ev<strong>en</strong>t:SQLEv<strong>en</strong>t):void<br />

{<br />

trace("the database op<strong>en</strong>ed successfully");<br />

}<br />

function errorHandler(ev<strong>en</strong>t:SQLErrorEv<strong>en</strong>t):void<br />

{<br />

if (ev<strong>en</strong>t.error.errorID == 3138)<br />

{<br />

trace("Incorrect <strong>en</strong>cryption key");<br />

}<br />

else<br />

{<br />

trace("Error message:", ev<strong>en</strong>t.error.message);<br />

trace("Details:", ev<strong>en</strong>t.error.details);<br />

}<br />

}<br />

The following example demonstrates op<strong>en</strong>ing an <strong>en</strong>crypted database in synchronous execution mode. For simplicity,<br />

in this example the <strong>en</strong>cryption key is hard-coded in the application code. However, this technique is strongly<br />

discouraged because it is not secure.<br />

Last updated 6/6/2012<br />

759

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

Saved successfully!

Ooh no, something went wrong!