0
votes

On the adobe website was this code:

var conn:SQLConnection = new SQLConnection(); var dbFile:File = File.applicationStorageDirectory.resolvePath("DBSample.db");

try { conn.open(dbFile); trace("the database was created successfully"); } catch (error:SQLError) { trace("Error message:", error.message); trace("Details:", error.details); }

on the line of

conn.open(dbFile);

there is an errorcode: 1120, Access of undefined property

Can anyone help? I just started with flex.

@aftee: Here is the whole mx:Script, it stays also between CDATA

import flash.data.SQLConnection; import flash.data.SQLStatement; import flash.events.SQLErrorEvent; import flash.events.SQLEvent; import flash.errors.SQLError; import flash.filesystem.File;

var conn:SQLConnection = new SQLConnection(); var dbFile:File = File.applicationStorageDirectory.resolvePath("DBSample.db");

try { conn.open(dbFile); trace("the database was created successfully"); } catch (error:SQLError) { trace("Error message:", error.message); trace("Details:", error.details); }
var createStmt:SQLStatement = new SQLStatement(); createStmt.sqlConnection = conn; var sql:String =
"CREATE TABLE IF NOT EXISTS employees (" +
" empId INTEGER PRIMARY KEY AUTOINCREMENT, " +
" firstName TEXT, " +
" lastName TEXT, " +
" salary NUMERIC CHECK (salary > 0)" +
")"; createStmt.text = sql; createStmt.addEventListener(SQLEvent.RESULT, createResult); createStmt.addEventListener(SQLErrorEvent.ERROR, createError); createStmt.execute(); function createResult(event:SQLEvent):void { trace("Table created"); } function createError(event:SQLErrorEvent):void { trace("Error message:", event.error.message); trace("Details:", event.error.details); }

1
can you paste all application code?! - afftee
or give a link to that adobe tutorial - afftee
do you develop in Flex Builder or Flash professional ? - afftee

1 Answers

0
votes

add to the mx:application tag this option: creationComplete="init()"

and put your code to this function

private function init():void {
var conn:SQLConnection = new SQLConnection(); 
var dbFile:File = File.applicationStorageDirectory.resolvePath("DBSample.db");

conn.open(dbFile);
...
}