簡體   English   中英

#1009錯誤Flash CC AS3

[英]#1009 Error Flash CC AS3

我一直在從事Flash as3上的游戲的開發,直到將所有變量重新排列在頂部以使其更易於閱讀之前,它的運行情況都非常理想。 現在,調試器在運行時對許多變量拋出錯誤1009,盡管它們的定義沒有更改。

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Main_fla::MainTimeline/Update()[Main_fla.MainTimeline::frame3:201]

錯誤指出我:

if (S) {
    legRot = 180;
}

盡管S和legRot都定義為;

var legRot:Number = 0;

var S:Boolean = false;

其余變量位於頂部f在框架上的動作。

感謝您的任何幫助,謝謝。

編輯
這是我的變量定義;

//Numbers
var currentAmmo = 1;
var xVel = 0;
var yVel = 0;
var xCollision = 0;
var yCollision = 0;
var enemySpeed = 4;
var ExplodeOnce = 0;
var EnemyWalking = 0;
var legRot = 0;
var dropxVel: Number = 0;
var dropyVel: Number = 0; 
var E = 0;

//Booleans
var A:Boolean = false;
var W:Boolean = false;
var S:Boolean = false;
var D:Boolean = false;
var SHIFT:Boolean = false;
var Q:Boolean = false;
var dead = false;

這是發生錯誤的地方;

    if (W) {
        legRot = 0;
    }
    if (A) {
        legRot = -90;
    }
    if (S) {
        legRot = 180;
    }
    if (D) {
        legRot = 90;
    }
    if (A && W) {
        legRot = -45
    };
    if (W && D) {
        legRot = 45
    };
    if (D && S) {
        legRot = 115
    };
    if (S && A) {
        legRot = -115
    };

    if (!dead){
        player.TopBody.rotation = Math.atan2(mouseY - player.y, mouseX - player.x) * 180 / Math.PI + 90;
        if (!W && !A && !S && !D) {
            player.BottomLegs.gotoAndStop(1);
            player.BottomLegs.rotation = Math.atan2(mouseY - player.y, mouseX - player.x) * 180 / Math.PI + 90;
        } else {
            player.BottomLegs.play();
            player.BottomLegs.rotation += (legRot - player.BottomLegs.rotation) / 4;
        }
    }

找到了問題。 在使用變量定義創建計時器之前,我不小心將事件監聽器添加到了計時器。 為什么這會在完全不同的偵聽器的更新函數中引發錯誤,這超出了我的范圍。 但是它現在固定了。
謝謝你們!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM