我试图为我的游戏创造高分。但是当我试图在 sqlite 上的表数据库上保存高分时,我有一些错误说 TypeError: Error #1009: Cannot access a property or method of a null object reference。在 DDRnew_fla::MainTimeline/ext()[DDRnew_fla.MainTimeline::frame26:64] 我的动作脚本是这样的
import flash.filesystem.File;
import flash.data.SQLStatement;
import flash.data.SQLConnection;
import flash.events.SQLEvent;
import flash.events.SQLErrorEvent;
import flash.data.SQLResult;
import flash.events.MouseEvent;
import flash.display.MovieClip;
var fileDB:File;
var koneksi:SQLConnection;
var sqlStatement:SQLStatement;
perfectcount.text = "" + int(perfect);
greatcount.text = "" + int(great);
goodcount.text = "" + int(good);
boocount.text = "" + int(boo);
misscount.text = "" + int(miss);
scorecount.text = "" + int(score);
addEventListener(Event.ENTER_FRAME, ranking);
exit.addEventListener(MouseEvent.CLICK, ext);
init();
function init()
{
koneksi = new SQLConnection();
koneksi.addEventListener(SQLEvent.OPEN, koneksiHandler);
koneksi.addEventListener(SQLErrorEvent.ERROR, errorHandler);
fileDB = new File(File.applicationDirectory.nativePath);
fileDB = fileDB.resolvePath("DDR.db");
koneksi.open(fileDB);
}
function koneksiHandler(e:SQLEvent)
{
sqlStatement = new SQLStatement();
sqlStatement.sqlConnection = koneksi;
sqlStatement.addEventListener(SQLErrorEvent.ERROR, errorHandler);
}
function ranking(event:Event):void
{
if (score>=846000)
{
rank.text = "A";
this.removeEventListener(Event.ENTER_FRAME, ranking);
}
else if (score>=658000)
{
rank.text = "B";
this.removeEventListener(Event.ENTER_FRAME, ranking);
}
else if (score>=470000)
{
rank.text = "C";
this.removeEventListener(Event.ENTER_FRAME, ranking);
}
else if (score>=282000)
{
rank.text = "D";
this.removeEventListener(Event.ENTER_FRAME, ranking);
}
else
{
rank.text = "E";
this.removeEventListener(Event.ENTER_FRAME, ranking);
}
}
function ext(e:MouseEvent):void
{
gotoAndStop("main menu");
var scoretxt:String ="" + int(score);
var ranktxt:String = rank.text;
var queryString:String;
queryString = "INSERT INTO easy1 (score, Rank) VALUES ('" + scoretxt + "', '" + ranktxt + "')";
var sqlQuery:String = queryString;
sqlStatement.addEventListener(SQLEvent.RESULT, querySukses);
sqlStatement.text = sqlQuery;
sqlStatement.execute();
}
function querySukses(e:SQLEvent)
{
sqlStatement.removeEventListener(SQLEvent.RESULT, querySukses);
e.target.removeEventListener(MouseEvent.CLICK, ext);
}
function errorHandler(e:*):void
{
trace("Eksekusi statement error.");
}
第 64 行是 var ranktxt:String = rank.text; 完美,伟大,好,嘘,小姐是可变的得分。我之前需要一个解决方案