Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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 需要使用hit test object函数删除子项_Actionscript 3 - Fatal编程技术网

Actionscript 3 需要使用hit test object函数删除子项

Actionscript 3 需要使用hit test object函数删除子项,actionscript-3,Actionscript 3,我正在尝试做一个函数,在这个函数中,我将一些种子放入一个桶中,然后将种子移除,但是该函数将只是种子与桶碰撞 我有两个对象作为movieclips,并且有一个基本的hitTestObject条件语句,我不知道为什么feed_mc不会被删除 if(bucket_mc.hitTestObject(feed_mc)) { if(stage.contains(feed_mc)) removeChild(feed_mc); } 先谢谢你 对不起,我应该在这里编辑 我

我正在尝试做一个函数,在这个函数中,我将一些种子放入一个桶中,然后将种子移除,但是该函数将只是种子与桶碰撞

我有两个对象作为movieclips,并且有一个基本的hitTestObject条件语句,我不知道为什么feed_mc不会被删除

    if(bucket_mc.hitTestObject(feed_mc))
    {
    if(stage.contains(feed_mc))
    removeChild(feed_mc);
    }
先谢谢你

对不起,我应该在这里编辑

我的代码

   var Necessities:Array = new Array (Seed, shelter, water);

   for(var i:int = 0; i< 10; i++)
   {
   var pickObjects = Necessities[int(Math.random()* Necessities.length)];
   var Objects:MovieClip = new pickObjects();
   addChild(Objects);

   Objects.x = Math.random() + 600;
   Objects.y = Math.random() * stage.stageHeight;

   }


   stage.addEventListener(Event.ENTER_FRAME, feedHen);


   function feedHen(e:Event):void {

   if(hen_mc.hitTestObject(Objects))

   {
    if (Objects.parent)
   Objects.parent.removeChild(Objects);
   }
   }
var必需品:数组=新数组(种子、庇护所、水);
对于(变量i:int=0;i<10;i++)
{
var pickObjects=Essentials[int(Math.random()*Essentials.length)];
var Objects:MovieClip=new pickObjects();
addChild(对象);
Objects.x=Math.random()+600;
Objects.y=Math.random()*stage.stageHeight;
}
stage.addEventListener(Event.ENTER_FRAME,feedHen);
函数feedHen(e:事件):无效{
if(hen_mc.hitTestObject(Objects))
{
if(Objects.parent)
Objects.parent.removeChild(对象);
}
}
看起来像

if(feed_mc.parent){
    feed_mc.parent.removeChild(feed_mc);
}
应该有帮助-如果您不确定
DisplayObjectContainer
是什么
parent

编辑
我认为这应该有效

var必需品:数组=新数组(种子、庇护所、水);
//在此处存储对象
var objectsVector:Vector.=新向量();
对于(变量i:int=0;i<10;i++){
var pickObjects=Essentials[int(Math.random()*Essentials.length)];
var Objects:MovieClip=new pickObjects();
addChild(对象);
objectsVector.push(对象);//添加到向量
Objects.x=Math.random()+600;
Objects.y=Math.random()*stage.stageHeight;
}
stage.addEventListener(Event.ENTER_FRAME,feedHen);
函数feedHen(e:事件):无效{
对于(var i:int=objectsVector.length-1;i>=0;i--){//循环存储的对象
if(hen_mc.hitTestObject(objectsVector[i])){
if(objectsVector[i].parent){
objectsVector[i].parent.removeChild(objectsVector[i]);
objectsVector.splice(i,1);//从存储器中删除
}
}
}   
}

但是,我建议检查一些鼠标事件,而不是
ENTER\u FRAME
,以减少函数调用的数量

stage.contains(feed\u mc)
是否为
true
?尝试
stage.removeChild(feed\u mc)
如果soI在stage上有feed\u mc,那么我猜这是真的,因为stage包含它。stage.removeChild(feed_mc)没有工作,仍然只是通过它
跟踪(feed_mc.parent)
将显示父对象
DisplayObjectContainer
。因此您需要删除
对象
?请您描述一下您试图实现的目标?在运行游戏之前,使用actionscript 3添加电影剪辑时,我似乎会将其删除。然而,它只会删除1个特定的电影剪辑,这是我的代码。变量必需品:数组=新数组(种子、庇护所、水);对于(var i:int=0;i<10;i++){var pickObjects=Essentials[int(Math.random()*Essentials.length)];var对象:MovieClip=new pickObjects();addChild(Objects);Objects.x=Math.random()+600;Objects.y=Math.random()*stage.stageHeight;}我尝试了这段代码,但是我的一些文本被删除了。这些对象似乎是在顶部生成的,大部分是在屏幕外生成的,我也遇到了这些错误。TypeError:Error#1006:push不是一个函数。flash.display::MovieClip/gotoAndStop()在flash.display::MovieClip/gotoAndStop()在littleredhen\u fla::main timeline/gogo()非常感谢你,你太棒了!如果我要添加一个var来计算被拾取的对象,我会在这段代码之外编码还是单独编码?@vectorfox欢迎您)如果您需要在
函数
/
for
循环外部(或者换句话说,不仅仅是内部)可以访问计数器,您应该在其外部创建它
    var Necessities:Array = new Array (Seed, shelter, water);
    //store Objects here
    var objectsVector:Vector.<MovieClip> = new Vector.<MovieClip>();
    for(var i:int = 0; i< 10; i++){
        var pickObjects = Necessities[int(Math.random()* Necessities.length)];
        var Objects:MovieClip = new pickObjects();
        addChild(Objects);      
        objectsVector.push(Objects);//add to Vector
        Objects.x = Math.random() + 600;
        Objects.y = Math.random() * stage.stageHeight;
    }

   stage.addEventListener(Event.ENTER_FRAME, feedHen);

    function feedHen(e:Event):void {
        for(var i: int = objectsVector.length - 1; i >= 0; i--){//loop through stored objects
            if(hen_mc.hitTestObject(objectsVector[i])){
                if (objectsVector[i].parent){
                    objectsVector[i].parent.removeChild(objectsVector[i]);
                    objectsVector.splice(i, 1);//remove from storage
                }
            }
        }   
    }