-1
我一直有麻煩,當我運行我的代碼和錯誤#1009彈出似乎停止我的代碼工作。我相信問題是當我的AddDalek()函數試圖爲臨時對象的x和y屬性賦值時。但是,我無法弄清楚如何解決這個問題。對解決方案的改變提供解決方案和解釋會很有幫助。AS3 Error#1009 Position Starts as null
此代碼僅僅是我爲學校製作的遊戲的開始,所以請隨時推薦對我的代碼進行任何更改。
僅供參考Cybermen,所有的Daleks,沉默,哭泣的天使是聯動的符號
import flash.events.*
import flash.display.*
var currentx = 229.95;
var currenty = 429.6;
var enemyspeed = 1;
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
return randomNum;
}
function AddCyberman(){
var tempobject:Cyberman = new Cyberman();
addChild (tempobject);
tempobject.x = currentx;
tempobject.y = currenty;
}
function AddSilence(){
var tempobject:Silence = new Silence();
addChild (tempobject);
tempobject.x = currentx;
tempobject.y = currenty;
}
function AddWeepingAngel(){
var i = randRange(1,2);
if (i == 1)
{
var tempobject:WeepingAngel1 = new WeepingAngel1();
addChild (tempobject);
tempobject.x = currentx;
tempobject.y = currenty;
}
else if (i == 2)
{
var tempobject1:WeepingAngel2 = new WeepingAngel2();
addChild (tempobject1);
tempobject.x = currentx;
tempobject.y = currenty;
}
}
function AddDalek()
{
var i = randRange (1,5);
if (i == 1)
{
var tempobject:BlueDalek = new BlueDalek();
addChild (tempobject);
tempobject.x = currentx;
tempobject.y = currenty;
}
else if (i == 2)
{
var tempobject1:YellowDalek = new YellowDalek();
addChild (tempobject1);
tempobject.x = currentx;
tempobject.y = currenty;
}
else if (i == 3)
{
var tempobject2:RedDalek = new RedDalek();
addChild (tempobject2);
tempobject.x = currentx;
tempobject.y = currenty;
}
else if (i == 4)
{
var tempobject3:GreenDalek = new GreenDalek();
addChild (tempobject3);
tempobject.x = currentx;
tempobject.y = currenty;
}
else if (i == 5)
{
var tempobject4:SilverDalek = new SilverDalek();
addChild (tempobject4);
tempobject.x = currentx;
tempobject.y = currenty;
}
}
function moveEnemys()
{
var templist2:Array = new Array()
var templist:Array = [Silence , Cyberman , WeepingAngel1 , WeepingAngel2 , BlueDalek , YellowDalek , RedDalek , GreenDalek , SilverDalek];
for (var i = 0; i < templist.length; i++)
{
if (templist[i])
{
templist2.push (templist[i]);
}
}
for (var t = 0; t < templist2.length; i++)
{
templist2[t].y += enemyspeed;
}
}
addEventListener (Event.ENTER_FRAME , function() {OnFrameReset()});
function OnFrameReset()
{
moveEnemys();
}
AddDalek();
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.tylerkasper::Engine/AddDalek()
at com.tylerkasper::Engine/frame1()
謝謝。我不敢相信這是一個簡單的錯誤。另外,感謝您在未來的調試信息。它確實有幫助。 – Chubzorz