在adobe网站上有这段代码:
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);
}
在
行
conn.open(dbFile);
有一个错误代码:1120,访问未定义的属性
有人可以帮忙吗?我刚刚开始使用flex。
@aftee: 这是整个mx:Script,它也保持在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”);
试
{
conn.open(DBFILE);
trace(“数据库已成功创建”);
}
catch(错误:SQLError)
{
trace(“错误消息:”,error.message);
trace(“Details:”,error.details);
}
var createStmt:SQLStatement = new SQLStatement();
createStmt.sqlConnection = conn;
var sql:String =
“创建表,如果不是员工(”+
“empid INTEGER PRIMARY KEY AUTOINCREMENT,”+
“firstName TEXT”,+
“lastName TEXT,”+
“薪水NUMERIC CHECK(工资> 0)”+
“)”;
createStmt.text = sql;
createStmt.addEventListener(SQLEvent.RESULT,createResult);
createStmt.addEventListener(SQLErrorEvent.ERROR,createError);
createStmt.execute();
function createResult(event:SQLEvent):void
{
trace(“表创建”);
}
function createError(event:SQLErrorEvent):void
{
trace(“错误消息:”,event.error.message);
trace(“Details:”,event.error.details);
}
答案 0 :(得分:0)
将mx:application标记添加到此选项:creationComplete="init()"
并将您的代码放入此功能
private function init():void {
var conn:SQLConnection = new SQLConnection();
var dbFile:File = File.applicationStorageDirectory.resolvePath("DBSample.db");
conn.open(dbFile);
...
}