Hello,
I’m using Flash CS5.5 to connect to an SQLite database called “base.db”.
The connection works fine and it can return values from the database, but only if i interrupt the test by clicking ctrl+enter again and then clicking “no” when it asks me to cancel.
IF i just let the test run then I get the following error:
Error: Error #3104: A SQLConnection must be open to perform this operation.
at Error$/throwError()
at flash.data::SQLStatement/checkAllowed()
at flash.data::SQLStatement/checkReady()
at flash.data::SQLStatement/execute()
at AdobeExamples_fla::MainTimeline/frame1()[AdobeExamples_fla.MainTimeline::frame1:36]
at runtime::ContentPlayer/loadInitialContent()
at runtime::ContentPlayer/playRawContent()
at runtime::ContentPlayer/playContent()
at runtime::AppRunner/run()
at ADLAppEntry/run()
at global/runtime::ADLEntry()
the database opened successfully
[UnloadSWF] AdobeExamples.swf
Test Movie terminated.
Here is the code:
import flash.data.SQLConnection;
import flash.data.SQLMode;
import flash.data.SQLResult;
import flash.data.SQLStatement;
import flash.errors.SQLError;
import flash.events.SQLErrorEvent;
import flash.events.SQLEvent;
import flash.filesystem.File;
import flash.data.SQLConnection;
import flash.events.SQLErrorEvent;
import flash.events.SQLEvent;
var conn:SQLConnection = new SQLConnection();
conn.addEventListener(SQLEvent.OPEN, openHandler);
conn.addEventListener(SQLErrorEvent.ERROR, errorHandler);
// The database file is in the application storage directory
var folder:File = File.applicationDirectory;
var dbFile:File = folder.resolvePath("base.db");
conn.openAsync(dbFile, SQLMode.UPDATE);
var selectStmt:SQLStatement = new SQLStatement();
// A SQLConnection named "conn" has been created previously
selectStmt.sqlConnection = conn;
selectStmt.text = "SELECT id, letter1, letter2, letter3 FROM tablewords";
selectStmt.addEventListener(SQLEvent.RESULT, resultHandler);
selectStmt.addEventListener(SQLErrorEvent.ERROR, errorHandler);
selectStmt.execute();
function resultHandler(event:SQLEvent):void
{
var result:SQLResult = selectStmt.getResult();
var numResults:int = result.data.length;
for (var i:int = 0; i < numResults; i++)
{
var row:Object = result.data*;
var output:String = "id: " + row.id;
output += "; letter1: " + row.letter1;
output += "; letter2: " + row.letter2;
output += "; letter3: " + row.letter3;
trace(output);
}
}
function openHandler(event:SQLEvent):void
{
trace("the database opened successfully");
}
function errorHandler(event:SQLErrorEvent):void
{
}
Can anyone tell me why this is happening?
I can’t help thinking that these last few days i’ve been going round in circles, and i might have had it right the first time.