Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3:TypeError:Error#1009:无法访问空对象引用的属性或方法。需要帮助_Actionscript 3_Flash_Debugging_Actionscript - Fatal编程技术网

Actionscript 3 AS3:TypeError:Error#1009:无法访问空对象引用的属性或方法。需要帮助

Actionscript 3 AS3:TypeError:Error#1009:无法访问空对象引用的属性或方法。需要帮助,actionscript-3,flash,debugging,actionscript,Actionscript 3,Flash,Debugging,Actionscript,我是ActionScript新手,我真的需要帮助调试这个问题。这是我运行代码时在输出上显示的内容: TypeError: Error #1009: Cannot access a property or method of a null object reference. at StreetHobogame_fla::MainTimeline/pickup() at StreetHobogame_fla::MainTimeline/gameloop() 这是我的代码: impo

我是ActionScript新手,我真的需要帮助调试这个问题。这是我运行代码时在输出上显示的内容:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at StreetHobogame_fla::MainTimeline/pickup()
    at StreetHobogame_fla::MainTimeline/gameloop()
这是我的代码:

import flash.events.KeyboardEvent;

stop();
guy.stop();

var enemySpeed:Number = 3;
var wspeed:Number = 0;
var vy:Number = 0;
var gv:Number = 1;
var jumped:Boolean = false;
var score:Number = 0;
var lives:Number = 5;




livesbox.text = lives.toString();

stage.addEventListener(Event.ENTER_FRAME,gameloop);

trace(ground.x);
var motionspeed:int = 30;

left.addEventListener(MouseEvent.MOUSE_DOWN, leftMove);
left.addEventListener(MouseEvent.MOUSE_UP, leftUp);
right.addEventListener(MouseEvent.MOUSE_DOWN, rightMove);
right.addEventListener(MouseEvent.MOUSE_UP, rightUp);
jumpButton.addEventListener(MouseEvent.MOUSE_DOWN, jumpPressed);

function jumpPressed(e:Event):void
{
    if (! jumped)
    {
        vy = -14;
        jumped = true;
    }
}

function rightUp(e:Event):void
{
    wspeed = 0;


}


function rightMove(e:Event):void
{
    wspeed +=  10;
    guy.gotoAndStop(2);
}


function leftMove(event:Event):void
{
    wspeed = -10;
    guy.gotoAndStop(1);
}

function leftUp(event:Event):void
{
    wspeed = 0;

}



function gameloop(e:Event)
{
    moveplayer();
    jumpgravity();
    exitlevel1();
    //exitlevel2();
    pickup();
    enemy();
    spikes();
    enemyMove();

    return (0);

}

function pickup()
{
    if (guy.hitTestObject(key))
    {
        key.visible = false;
    }
    if (guy.hitTestObject(coin1))
    {
        coin1.x = 2000;
        score++;
        scorebox.text = score.toString();
    }
    if (guy.hitTestObject(coin2))
    {
        coin2.x = 2000;
        score++;
        scorebox.text = score.toString();
    }
    if (guy.hitTestObject(coin3))
    {
        coin3.x = 2000;
        score++;
        scorebox.text = score.toString();
    }
    if (guy.hitTestObject(coin4))
    {
        coin4.x = 2000;
        score++;
        scorebox.text = score.toString();
    }
}



function moveplayer()
{
    guy.x +=  wspeed;

    if (guy.x < 0)
    {
        guy.x = 0;
    }
    if (guy.x > 1024)
    {
        guy.x = 1024;
    }
}

function jumpgravity()
{
    vy +=  gv;
    if (! ground.hitTestPoint(guy.x,guy.y,true))
    {
        guy.y +=  vy;
    }
    if (ground.hitTestPoint(guy.x,guy.y,true))
    {

        guy.y--;
        vy = 0;
        jumped = false;

    }
}



function exitlevel1()
{
    if (guy.hitTestObject(exitMC))
    {
        if (key.visible == false)
        {
            stage.removeEventListener(Event.ENTER_FRAME,gameloop);
            left.removeEventListener(MouseEvent.MOUSE_DOWN, leftMove);
            left.removeEventListener(MouseEvent.MOUSE_UP, leftUp);
            right.removeEventListener(MouseEvent.MOUSE_DOWN, rightMove);
            right.removeEventListener(MouseEvent.MOUSE_UP, rightUp);
             jumped= false;
            wspeed = 0;
            guy.gotoAndStop(1);
            gotoAndStop(1,"level1Questions");



        }

    }

}
/*function exitlevel2()
{
    if (guy.hitTestObject(exit2MC))
    {
        if (key.visible == false)
        {
             jumped= false;
            wspeed = 0;
            guy.gotoAndStop(1);
            gotoAndStop(1,"level2Complete");



        }

    }

}
*/
function enemy()
{
    if (guy.hitTestObject(enemy1))
    {
        guy.x = 520.95;
        guy.y = 425.50;
        if (lives<=1)
        {
            lives = 0;
            gotoAndStop(1,"GameOver");
        }
        else
        {
            lives--;
            livesbox.text = lives.toString();
        }

    }
}

function spikes()
{
    if (guy.hitTestObject(Spike))
    {
        guy.x = 520;
        guy.y = 425.5;
        if (lives<=1)
        {
            lives = 0;
            gotoAndStop(1,"GameOver");
        }
        else
        {


            lives--;
            livesbox.text = lives.toString();
        }
    }
}


function enemyMove():void
{
    enemy1.x +=  enemySpeed;
    if (enemy1.x >= 350)
    {
        enemySpeed *=  -1;
        enemy1.scaleX *=  -1;

    }
    else if (enemy1.x < 60)
    {
        enemySpeed *=  -1;
        enemy1.scaleX *=  -1;

    }
}
导入flash.events.KeyboardEvent;
停止();
盖伊,住手;
var-enemySpeed:Number=3;
var wspeed:Number=0;
变量vy:Number=0;
var gv:数值=1;
var:Boolean=false;
var得分:数字=0;
var寿命:数字=5;
livesbox.text=lifes.toString();
stage.addEventListener(事件输入帧,gameloop);
痕迹(地面x);
无功运动速度:int=30;
left.addEventListener(MouseEvent.MOUSE_DOWN,leftMove);
left.addEventListener(MouseEvent.MOUSE\u UP,leftUp);
right.addEventListener(MouseEvent.MOUSE_DOWN,rightMove);
right.addEventListener(MouseEvent.MOUSE\u UP,rightUp);
jumpButton.addEventListener(MouseEvent.MOUSE_DOWN,jumpPressed);
按下功能跳线(e:事件):无效
{
如果(!跳)
{
vy=-14;
跳跃=正确;
}
}
函数rightUp(e:事件):无效
{
wspeed=0;
}
功能rightMove(e:事件):无效
{
wspeed+=10;
guy.gotoAndStop(2);
}
函数leftMove(事件:事件):void
{
wspeed=-10;
guy.gotoAndStop(1);
}
函数leftUp(事件:事件):void
{
wspeed=0;
}
函数gameloop(e:事件)
{
moveplayer();
跳跃重力();
exitlevel1();
//exitlevel2();
拾音器();
敌人();
尖峰();
灌肠移动();
返回(0);
}
函数拾取()
{
if(guy.hitTestObject(键))
{
key.visible=false;
}
if(guy.hitTestObject(coin1))
{
coin1.x=2000;
分数++;
scorebox.text=score.toString();
}
if(guy.hitTestObject(coin2))
{
coin2.x=2000;
分数++;
scorebox.text=score.toString();
}
if(guy.hitTestObject(coin3))
{
coin3.x=2000;
分数++;
scorebox.text=score.toString();
}
if(guy.hitTestObject(coin4))
{
coin4.x=2000;
分数++;
scorebox.text=score.toString();
}
}
函数moveplayer()
{
guy.x+=wspeed;
if(guy.x<0)
{
guy.x=0;
}
如果(guy.x>1024)
{
guy.x=1024;
}
}
函数jumpgravity()
{
vy+=gv;
if(!ground.hitTestPoint(guy.x,guy.y,true))
{
guy.y+=vy;
}
if(ground.hitTestPoint(guy.x,guy.y,true))
{
盖伊;
vy=0;
跳跃=假;
}
}
函数exitlevel1()
{
if(guy.hitTestObject(exitMC))
{
如果(key.visible==false)
{
stage.removeEventListener(事件。输入\u帧,gameloop);
left.removeEventListener(MouseEvent.MOUSE_向下,leftMove);
left.removeEventListener(MouseEvent.MOUSE_UP,leftUp);
right.removeEventListener(MouseEvent.MOUSE_DOWN,rightMove);
right.removeEventListener(MouseEvent.MOUSE_UP,rightUp);
跳跃=假;
wspeed=0;
guy.gotoAndStop(1);
gotoAndStop(1级,“1级问题”);
}
}
}
/*函数exitlevel2()
{
if(guy.hitTestObject(exit2MC))
{
如果(key.visible==false)
{
跳跃=假;
wspeed=0;
guy.gotoAndStop(1);
gotoAndStop(1,“2级完成”);
}
}
}
*/
功能敌人()
{
if(guy.hitTestObject(enemy1))
{
guy.x=520.95;
盖y=425.50;

当执行
pickup()
函数时,如果(lives此变量中至少有一个为空:

  • 家伙
  • 钥匙
  • 硬币1
  • 记分箱
  • 硬币2
  • 硬币3
  • 硬币4
您可以使用
trace()
函数检查哪一个

function pickup()
{
    trace('guy==' + guy);
    trace('key==' + key);
    trace('scorebox==' + scorebox);
    trace('coin1==' + coin1);
    trace('coin2==' + coin2);
    trace('coin3==' + coin3);
    trace('coin4==' + coin4);

    if (guy.hitTestObject(key))
    {
        key.visible = false;
    }
    if (guy.hitTestObject(coin1))
    {
        coin1.x = 2000;
        score++;
        scorebox.text = score.toString();
    }
    if (guy.hitTestObject(coin2))
    {
        coin2.x = 2000;
        score++;
        scorebox.text = score.toString();
    }
    if (guy.hitTestObject(coin3))
    {
        coin3.x = 2000;
        score++;
        scorebox.text = score.toString();
    }
    if (guy.hitTestObject(coin4))
    {
        coin4.x = 2000;
        score++;
        scorebox.text = score.toString();
    }
}

请查看此问题右侧相关列下的827个问题-它们将帮助您理解此错误。