Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.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 为什么在对已定义对象执行“hitTest”时收到空错误?_Actionscript 3_Flash_Flash Cs3 - Fatal编程技术网

Actionscript 3 为什么在对已定义对象执行“hitTest”时收到空错误?

Actionscript 3 为什么在对已定义对象执行“hitTest”时收到空错误?,actionscript-3,flash,flash-cs3,Actionscript 3,Flash,Flash Cs3,我所要做的就是从舞台上移除一些孩子,但它给了我一个空错误: TypeError: Error #2007: Parameter hitTestObject must be non-null. at flash.display::DisplayObject/flash.display:DisplayObject::_hitTest() at flash.display::DisplayObject/hitTestObject() at SpaceOddessey_fla::MainTimeline

我所要做的就是从舞台上移除一些孩子,但它给了我一个空错误:

TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/flash.display:DisplayObject::_hitTest()
at flash.display::DisplayObject/hitTestObject()
at SpaceOddessey_fla::MainTimeline/GreenMove()
我不明白为什么会发生这种情况,因为我在“Green Guy”的移动/移除函数上方的函数中定义了对象。我不能继续这个项目,直到我得到这个固定,因为我需要使用它为我的其余精灵以及

这是我的密码

stop();

//do this three times (for each space dude)
//GREEN
var MaxGreen:int = 1;
//Here we declare the speed of these cannon balls
var GreenVelocityX:Array = new Array();
var GreenVelocityY:Array = new Array();
//keep track of how many green guys
var GreenCount:int = 0;
var GreenSprite:Sprite;//declare a global variable for the cannonBall sprite.
var theGreen:Green_Guy;
//create the array thats holds the green guys
var myGreenGuyArray:Array = new Array(); 



//YELLOW
var MaxYellow:int = 1;
//Here we declare the speed of these cannon balls
var YellowVelocityX:Array = new Array();
var YellowVelocityY:Array = new Array();
//keep track of how many yellow guys
var YellowCount:int = 0;
var YellowSprite:Sprite;//declare a global variable for the cannonBall sprite.
var theYellow:Yellow_Guy;
//create the array thats holds the yellow guys
var myYellowGuyArray:Array = new Array();



//BABY
var MaxBabies:int = 1;
//Here we declare the speed of these cannon balls
var BabyVelocityX:Array = new Array();
var BabyVelocityY:Array = new Array();
//keep track of how many baby guys
var BabyCount:int = 0;
var BabySprite:Sprite;//declare a global variable for the cannonBall sprite.
var theBaby:Baby_Guy;
//create the array thats holds the baby guys
var myBabyGuyArray:Array = new Array();



//SPACE SHIP
var MaxShips:int = 4;
//Here we declare the speed of these cannon balls
var ShipVelocityX:Array = new Array();
var ShipVelocityY:Array = new Array();
//keep track of how many baby guys
var ShipCount:int = 0;
var ShipSprite:Sprite;//declare a global variable for the cannonBall sprite.
var theShip:space_ship;
//create the array thats holds the baby guys
var ShipArray:Array = new Array();


//ASTEROID
var MaxRocks:int = 6;
//Here we declare the speed of these cannon balls
var RockVelocityX:Array = new Array();
var RockVelocityY:Array = new Array();
//keep track of how many baby guys
var RockCount:int = 0;
var RockSprite:Sprite;//declare a global variable for the cannonBall sprite.
var theRock:rock;
//create the array thats holds the baby guys
var RockArray:Array = new Array();

yellow_btn.addEventListener(MouseEvent.CLICK, ClickHandle);
green_btn.addEventListener(MouseEvent.CLICK, ClickHandle);
baby_btn.addEventListener(MouseEvent.CLICK, ClickHandle);
function ClickHandle(targetEvent:MouseEvent):void
{
    if(targetEvent.target == yellow_btn)
    {
        MaxYellow += 1;

        stage.addEventListener(Event.ENTER_FRAME,makeYellow);
    }
    else if(targetEvent.target == green_btn)
    {
        MaxGreen += 1;
        stage.addEventListener(Event.ENTER_FRAME,makeGreen);
    }
    else if(targetEvent.target == baby_btn)
    {
        MaxBabies += 1;
        stage.addEventListener(Event.ENTER_FRAME,makeBaby);
    }
}

stage.addEventListener(Event.ENTER_FRAME,makeShips);

function makeShips(Space:Event){
    //Create the Enemies if there are less then 100
    if (ShipCount < MaxShips){
        //create our sprites
        ShipSprite = new Sprite();
        stage.addChild(ShipSprite);
        theShip = new space_ship();
        ShipSprite.addChild(theShip);

        ShipSprite.x = Math.random() * 500;//width ~ 81.7
        ShipSprite.y = Math.random() * 300;

        //allows a scaler of making objects from big to small
        //BabySprite.scaleX = BabySprite.scaleY = Math.random() * 1.3;

        ShipArray[ShipCount] = ShipSprite;
        ShipCount += 1;

        stage.addEventListener(Event.ENTER_FRAME,ShipMove);
        }

        //end for loop
    }
function ShipMove(go:Event):void
{
    for(var s=0; s<ShipCount; s++)
    {
        ShipVelocityX[s] = -3;
        ShipVelocityY[s] = -1;
        /*if(my)
        {

        }*/
        ShipArray[s].x += ShipVelocityX[s];
        //myYellowGuyArray[a].y += YellowVelocityY[a];
        if (ShipArray[s].x > 550)
        {
            ShipArray[s].x = 0 - ShipArray[s].width;
        }
        else if(ShipArray[s].x + ShipArray[s].width < 0)
        {
            ShipArray[s].x = 500;
        }
        if(ShipArray[s].y > 400)
        {
            ShipArray[s].y = 0 - ShipArray[s].height;
        }
        else if(ShipArray[s].y + ShipArray[s].height < 0)
        {
            ShipArray[s].y = 400;
        }
    }
}

stage.addEventListener(Event.ENTER_FRAME,makeBaby);

function makeBaby(DudeEvent:Event){
    //Create the Enemies if there are less then 100
    if (BabyCount < MaxBabies){
        //create our sprites
        BabySprite = new Sprite();
        stage.addChild(BabySprite);
        theBaby = new Baby_Guy();
        BabySprite.addChild(theBaby);

        BabySprite.x = Math.random() * 500;//width ~ 81.7
        BabySprite.y = Math.random() * 300;

        //allows a scaler of making objects from big to small
        //BabySprite.scaleX = BabySprite.scaleY = Math.random() * 1.3;

        myBabyGuyArray[BabyCount] = BabySprite;
        BabyCount += 1;
        //trace(myEnemies.length);

        stage.addEventListener(Event.ENTER_FRAME,BabyMove);
        }

        //end for loop
    }
function BabyMove(go:Event):void
{
    for(var i=0; i<BabyCount; i++)
    {
        BabyVelocityX[i] = 5;
        BabyVelocityY[i] = 2;
        /*if(my)
        {

        }*/
        myBabyGuyArray[i].x += BabyVelocityX[i];
        myBabyGuyArray[i].y += BabyVelocityY[i];
        myBabyGuyArray[i].rotation += 2;
        if (myBabyGuyArray[i].x > 550)
        {
            myBabyGuyArray[i].x = 0 - myBabyGuyArray[i].width;
        }
        else if(myBabyGuyArray[i].x + myBabyGuyArray[i].width < 0)
        {
            myBabyGuyArray[i].x = 500;
        }
        if(myBabyGuyArray[i].y > 400)
        {
            myBabyGuyArray[i].y = 0 - myBabyGuyArray[i].height;
        }
        else if(myBabyGuyArray[i].y + myBabyGuyArray[i].height < 0)
        {
            myBabyGuyArray[i].y = 400;
        }
        for(var v:int=0; v<RockCount; v++)
        {
            if(RockArray[v].hitTestObject(myBabyGuyArray[i]))
            {
                //trace('hey')
                BabyVelocityX[i] = 100;
            }
        }
    }
}

stage.addEventListener(Event.ENTER_FRAME,makeYellow);

function makeYellow(Dude:Event){
    //Create the Enemies if there are less then 100
    if (YellowCount < MaxYellow){
        //create our sprites
        YellowSprite = new Sprite();
        stage.addChild(YellowSprite);
        theYellow = new Yellow_Guy();
        YellowSprite.addChild(theYellow);

        YellowSprite.x = Math.random() * 500;//width ~ 81.7
        YellowSprite.y = Math.random() * 300;

        //allows a scaler of making objects from big to small
        //BabySprite.scaleX = BabySprite.scaleY = Math.random() * 1.3;

        myYellowGuyArray[YellowCount] = YellowSprite;
        YellowCount += 1;

        stage.addEventListener(Event.ENTER_FRAME,YellowMove);
        }

        //end for loop
    }
function YellowMove(go:Event):void
{
    for(var a=0; a<YellowCount; a++)
    {
        YellowVelocityX[a] = -3;
        YellowVelocityY[a] = -1;
        /*if(my)
        {

        }*/
        myYellowGuyArray[a].x += YellowVelocityX[a];
        myYellowGuyArray[a].y += YellowVelocityY[a];
        myYellowGuyArray[a].rotation += 1;
        if (myYellowGuyArray[a].x > 550)
        {
            myYellowGuyArray[a].x = 0 - myYellowGuyArray[a].width;
        }
        else if(myYellowGuyArray[a].x + myYellowGuyArray[a].width < 0)
        {
            myYellowGuyArray[a].x = 500;
        }
        if(myYellowGuyArray[a].y > 400)
        {
            myYellowGuyArray[a].y = 0 - myYellowGuyArray[a].height;
        }
        else if(myYellowGuyArray[a].y + myYellowGuyArray[a].height < 0)
        {
            myYellowGuyArray[a].y = 400;
        }
        for(var u:int=0; u<RockCount; u++)
        {
            if(RockArray[u].hitTestObject(myYellowGuyArray[a]))
            {
                YellowVelocityX[a] *= -1;
            }
        }
    }
}

stage.addEventListener(Event.ENTER_FRAME,makeGreen);

function makeGreen(Evnt:Event){
    //Create the Enemies if there are less then 100
    if (GreenCount < MaxGreen){
        //create our sprites
        GreenSprite = new Sprite();
        stage.addChild(GreenSprite);
        theGreen = new Green_Guy();
        GreenSprite.addChild(theGreen);

        GreenSprite.x = Math.random() * 500;//width ~ 81.7
        GreenSprite.y = Math.random() * 300;

        //allows a scaler of making objects from big to small
        //BabySprite.scaleX = BabySprite.scaleY = Math.random() * 1.3;

        myGreenGuyArray[GreenCount] = GreenSprite;
        GreenCount += 1;

        stage.addEventListener(Event.ENTER_FRAME,GreenMove);
        }
        //end for loop
    }
function GreenMove(go:Event):void
{
    for(var b:int=0; b<GreenCount; b++)
    {
        GreenVelocityX[b] = 7;
        GreenVelocityY[b] = -4;

        myGreenGuyArray[b].x += GreenVelocityX[b];
        myGreenGuyArray[b].y += GreenVelocityY[b];
        myGreenGuyArray[b].rotation -= 1;
        if (myGreenGuyArray[b].x > 550)
        {
            myGreenGuyArray[b].x = 0 - myGreenGuyArray[b].width;
        }
        else if(myGreenGuyArray[b].x + myGreenGuyArray[b].width < 0)
        {
            myGreenGuyArray[b].x = 500;
        }
        if(myGreenGuyArray[b].y > 400)
        {
            myGreenGuyArray[b].y = 0 - myGreenGuyArray[b].height;
        }
        else if(myGreenGuyArray[b].y + myGreenGuyArray[b].height < 0)
        {
            myGreenGuyArray[b].y = 400;
        }
        for(var z:int=0; z<ShipCount; z++)
        {
            //if(myGreenGuyArray[b] == null)
            {
                if(ShipArray[z].hitTestObject(myGreenGuyArray[b]))
                {
                    //if(GreenCount > 1)
                    //{
                        myGreenGuyArray[b].y = -50;
                        stage.removeChild(myGreenGuyArray[b]);
                        myGreenGuyArray.splice(b,1);
                        GreenCount--;
                        //b--;
                    //}
                }
            }
        }
        for(var g:int=0; g<RockCount; g++)
        {
            if(RockArray[g].hitTestObject(myGreenGuyArray[b]))
            {
                GreenVelocityX[b] *= -1;
            }
        }
    }
}

stage.addEventListener(Event.ENTER_FRAME,makeRocks);

function makeRocks(RockHard:Event){
    //Create the Enemies if there are less then 100
    if (RockCount < MaxRocks){
        //create our sprites
        RockSprite = new Sprite();
        stage.addChild(RockSprite);
        theRock = new rock();
        RockSprite.addChild(theRock);

        RockSprite.x = Math.random() * 500;//width ~ 81.7
        RockSprite.y = Math.random() * 300;

        //allows a scaler of making objects from big to small
        //BabySprite.scaleX = BabySprite.scaleY = Math.random() * 1.3;

        RockArray[RockCount] = RockSprite;
        RockCount += 1;

        stage.addEventListener(Event.ENTER_FRAME,RockMove);
        }

        //end for loop
    }
function RockMove(go:Event):void
{
    for(var r=0; r<RockCount; r++)
    {
        RockVelocityX[r] = 7;
        RockVelocityY[r] = 3;
        /*if(my)
        {

        }*/
        RockArray[r].x += RockVelocityX[r];
        //RockArray[r].y += RockVelocityY[r];
        if (RockArray[r].x > 550)
        {
            RockArray[r].x = 0 - RockArray[r].width;
        }
        else if(RockArray[r].x + RockArray[r].width < 0)
        {
            RockArray[r].x = 500;
        }
        if(RockArray[r].y > 400)
        {
            RockArray[r].y = 0 - RockArray[r].height;
        }
        else if(RockArray[r].y + RockArray[r].height < 0)
        {
            RockArray[r].y = 400;
        }
    }
}
stop();
//这样做三次(针对每个太空人)
//绿色的
var MaxGreen:int=1;
//这里我们宣布这些炮弹的速度
var GreenVelocityX:Array=new Array();
var GreenVelocityY:Array=new Array();
//记录有多少环保人士
变量GreenCount:int=0;
绿宝石:雪碧//为炮弹精灵声明一个全局变量。
绿色:绿色的家伙;
//创建一个容纳绿色人物的阵列
var myGreenGuyArray:Array=newarray();
//黄色的
var MaxYellow:int=1;
//这里我们宣布这些炮弹的速度
var YellowVelocityX:Array=new Array();
var YellowVelocityY:Array=new Array();
//记下有多少黄色的家伙
变量YellowCount:int=0;
变种黄雪碧:雪碧//为炮弹精灵声明一个全局变量。
黄种人:黄种人;
//创建容纳黄色人物的阵列
var myYellowGuyArray:Array=newarray();
//宝贝
var-MaxBabies:int=1;
//这里我们宣布这些炮弹的速度
var BabyVelocityX:Array=new Array();
var BabyVelocityY:Array=new Array();
//记录有多少男婴
var BabyCount:int=0;
var BabySprite:雪碧//为炮弹精灵声明一个全局变量。
var theBaby:Baby_Guy;
//创建容纳婴儿的阵列
var myBabyGuyArray:Array=newarray();
//宇宙飞船
var-MaxShips:int=4;
//这里我们宣布这些炮弹的速度
var ShipVelocityX:Array=new Array();
var ShipVelocityY:Array=new Array();
//记录有多少男婴
var ShipCount:int=0;
雪碧:雪碧//为炮弹精灵声明一个全局变量。
船型:太空船;
//创建容纳婴儿的阵列
var ShipArray:Array=newarray();
//小行星
var MaxRocks:int=6;
//这里我们宣布这些炮弹的速度
var RockVelocityX:Array=new Array();
var RockVelocityY:Array=new Array();
//记录有多少男婴
var岩石计数:int=0;
雪碧:雪碧//为炮弹精灵声明一个全局变量。
岩石:岩石;
//创建容纳婴儿的阵列
var RockArray:Array=newarray();
黄色\u btn.addEventListener(MouseEvent.CLICK,ClickHandle);
绿色\u btn.addEventListener(MouseEvent.CLICK,ClickHandle);
baby_btn.addEventListener(MouseEvent.CLICK,ClickHandle);
函数ClickHandle(targetEvent:MouseeEvent):无效
{
如果(targetEvent.target==黄色_btn)
{
MaxYellow+=1;
stage.addEventListener(事件。输入\u帧,使黄色);
}
else if(targetEvent.target==绿色)
{
MaxGreen+=1;
stage.addEventListener(事件。输入_帧,变为绿色);
}
else if(targetEvent.target==baby_btn)
{
最大值+=1;
stage.addEventListener(事件。输入\u帧,生成婴儿);
}
}
stage.addEventListener(事件。输入_帧,生成);
函数makeShips(空间:事件){
//如果数量少于100,则创建敌人
如果(发货数量<最大发货量){
//创造我们的精灵
ShipSprite=新精灵();
stage.addChild(ShipSprite);
飞船=新太空船();
ShipSprite.addChild(船舶);
ShipSprite.x=Math.random()*500;//宽度~81.7
ShipSprite.y=Math.random()*300;
//允许缩放器从大到小缩放对象
//BabySprite.scaleX=BabySprite.scaleY=Math.random()*1.3;
ShipArray[ShipCount]=ShipSprite;
船次+=1;
stage.addEventListener(事件。输入\u帧,ShipMove);
}
//循环结束
}
函数ShipMove(go:Event):无效
{
对于(var s=0;s 550)
{
ShipArray[s]。x=0-ShipArray[s]。宽度;
}
else if(ShipArray[s].x+ShipArray[s].宽度<0)
{
ShipArray[s].x=500;
}
如果(ShipArray[s].y>400)
{
ShipArray[s]。y=0-ShipArray[s]。高度;
}
else if(ShipArray[s].y+ShipArray[s].高度<0)
{
ShipArray[s].y=400;
}
}
}
stage.addEventListener(事件。输入\u帧,生成婴儿);
函数makeBaby(DudeEvent:Event){
//如果数量少于100,则创建敌人
if(婴儿计数<最大婴儿数){
//创造我们的精灵
BabySprite=新精灵();
阶段:addChild(BabySprite);
theBaby=新生婴儿;
婴儿普里特。添加孩子(婴儿);
BabySprite.x=Math.random()*500;//宽度~81.7
BabySprite.y=Math.random()*300;
//允许缩放器从大到小缩放对象
//BabySprite.scaleX=BabySprite.scaleY=Math.random()*1.3;
myBabyGuyArray[BabyCount]=BabySprite;
婴儿计数+=1;
//痕迹(myEnemies.长度);
stage.addEventListener(事件。输入帧,BabyMove);
}
//循环结束
}
函数BabyMove(go:Event):void
{
对于(变量i=0;i 550)
{
myBabyGuyArray[i].x=0-myBabyGuyArray[i].宽度;
}
else if(myBabyGuyArray[i].x+myBabyGuyArray[i].width<0)
{
myBabyGuyArray[i].x=500;
}
if(myBabyGuyArray[i].y>400)
{
myBabyGuyArray[i].y=0-myBabyGuyArray[i].高度;
}
else if(myBabyGuyArray[i].y+myBabyGuyArray[i].height<0)
{
myBabyGuyArray[i].y=400;
}
对于(变量v:int=0;v 400)
{
myYellowGuyArray[a]。y=0-myYellowGuyArray[a]。高度;
}
else if(myYellowGuyArray[a].y+myYellowGuyArray[a].height<0)
{
myYellowGuyArray[a].y=400;
}
对于(变量u:int=0;u 400
if(ShipArray[z].hitTestObject(myGreenGuyArray[b]))
if(RockArray[g].hitTestObject(myGreenGuyArray[b]))
myGreenGuyArray.splice(b,1);
trace([1,2,3][37] == null); // does the result of accessing an element that doesn't exist equal null?