Actionscript 3 Actionscript 3.0如何从addChild定义对象?

Actionscript 3 Actionscript 3.0如何从addChild定义对象?,actionscript-3,flash,actionscript,adobe,Actionscript 3,Flash,Actionscript,Adobe,所以基本上我想让一个男孩吃掉一些用addChild生成的蘑菇。我做了一个测试。但我有一个未定义属性的错误1120。我怎样才能解决这个问题?任何帮助都将不胜感激 这是我的密码 var timer:Timer = new Timer(1000,10); timer.addEventListener(TimerEvent.TIMER, addTarget); timer.start(); var score:int = 0; function addTarget(e:TimerEvent)

所以基本上我想让一个男孩吃掉一些用addChild生成的蘑菇。我做了一个测试。但我有一个未定义属性的错误1120。我怎样才能解决这个问题?任何帮助都将不胜感激

这是我的密码

    var timer:Timer = new Timer(1000,10);
timer.addEventListener(TimerEvent.TIMER, addTarget);
timer.start();

var score:int = 0;

function addTarget(e:TimerEvent)
{
    var posX = Math.random()*860;
    var posY = Math.random()*500;


    var mushroom:Mushroom = new Mushroom();
    addChild(mushroom);


    mushroom.x = posX;
    mushroom.y = posY;
    boy_mc.addEventListener(Event.ENTER_FRAME, scoring);
}


function scoring(e:Event)
{
    trace("test");
    if (boy_mc.hitTestObject(mushroom))

    {
    score = score + (MovieClip(e.currentTarget).point);

    score_txt.text = String(score);
    }
}
----------------这是我的班级档案----------


您需要蘑菇引用,比如
数组()
向量。(
)。然后,访问的
中的参考

var mushrooms:Vector.<Mushrooms> = new Vector.<Mushrooms>();

var timer:Timer = new Timer(1000,10);
timer.addEventListener(TimerEvent.TIMER, addTarget);
timer.start();

var score:int = 0;

function addTarget(e:TimerEvent) {

    var posX = Math.random()*860;
    var posY = Math.random()*500;

    var mushroom:Mushroom = new Mushroom();
    mushrooms.push(mushroom); //add the new mushroom in vector
    addChild(mushroom);

    mushroom.x = posX;
    mushroom.y = posY;
    boy_mc.addEventListener(Event.ENTER_FRAME, scoring);

}


function scoring(e:Event) {

    var totalMushrooms:int = mushrooms.length;

    for(var i:int = 0; i < totalMushrooms; i++) {
        if (boy_mc.hitTestObject(mushrooms[i])) { //mushroom reference
            score = score + (MovieClip(e.currentTarget).point);
            score_txt.text = String(score);
            removeChild(mushrooms[i]); //remove
            mushrooms.splice(i, 1); //remove mushroom from vector
        }   
    }

}
var:Vector.=新向量();
var定时器:定时器=新定时器(1000,10);
timer.addEventListener(TimerEvent.timer,addTarget);
timer.start();
变量得分:int=0;
函数addTarget(e:TimerEvent){
var posX=Math.random()*860;
var posY=Math.random()*500;
变种蘑菇:蘑菇=新蘑菇();
蘑菇。推(蘑菇);//在向量中添加新蘑菇
addChild(蘑菇);
蘑菇.x=posX;
蘑菇,y=posY;
boy_mc.addEventListener(事件输入帧,评分);
}
功能评分(e:事件){
var TotalMusligs:int=蘑菇.length;
对于(变量i:int=0;i
您需要蘑菇引用,比如
数组()
向量。(
)。然后,访问
中的参考

var mushrooms:Vector.<Mushrooms> = new Vector.<Mushrooms>();

var timer:Timer = new Timer(1000,10);
timer.addEventListener(TimerEvent.TIMER, addTarget);
timer.start();

var score:int = 0;

function addTarget(e:TimerEvent) {

    var posX = Math.random()*860;
    var posY = Math.random()*500;

    var mushroom:Mushroom = new Mushroom();
    mushrooms.push(mushroom); //add the new mushroom in vector
    addChild(mushroom);

    mushroom.x = posX;
    mushroom.y = posY;
    boy_mc.addEventListener(Event.ENTER_FRAME, scoring);

}


function scoring(e:Event) {

    var totalMushrooms:int = mushrooms.length;

    for(var i:int = 0; i < totalMushrooms; i++) {
        if (boy_mc.hitTestObject(mushrooms[i])) { //mushroom reference
            score = score + (MovieClip(e.currentTarget).point);
            score_txt.text = String(score);
            removeChild(mushrooms[i]); //remove
            mushrooms.splice(i, 1); //remove mushroom from vector
        }   
    }

}
var:Vector.=新向量();
var定时器:定时器=新定时器(1000,10);
timer.addEventListener(TimerEvent.timer,addTarget);
timer.start();
变量得分:int=0;
函数addTarget(e:TimerEvent){
var posX=Math.random()*860;
var posY=Math.random()*500;
变种蘑菇:蘑菇=新蘑菇();
蘑菇。推(蘑菇);//在向量中添加新蘑菇
addChild(蘑菇);
蘑菇.x=posX;
蘑菇,y=posY;
boy_mc.addEventListener(事件输入帧,评分);
}
功能评分(e:事件){
var TotalMusligs:int=蘑菇.length;
对于(变量i:int=0;i
error:is在未定义属性蘑菇的“if(boy_mc.hitTestObject(蘑菇))”访问中。为了完成,您应该通过编辑未定义属性蘑菇的“if(boy_mc.hitTestObject(蘑菇))”访问中的错误:is在未定义属性蘑菇的“if(boy_mc.hitTestObject(蘑菇))访问中。为了完成,您应该通过编辑将错误消息添加到问题本身