Arrays 如何在电影剪辑中播放电影剪辑?

Arrays 如何在电影剪辑中播放电影剪辑?,arrays,actionscript-3,flash,actionscript,movieclip,Arrays,Actionscript 3,Flash,Actionscript,Movieclip,我有一个名为“trainglePoint”的电影剪辑链接在一个带有“bgdemo”实例的movieclip中,我想知道如何让“trianglePoint”工作 此外,“gags”是将获得“三角形点”的角色 下面是我的代码,不起作用 谢谢 编辑:忘记添加“三角点”被多次放在舞台上(不知道这是否有帮助) var pickUpsArray:Array=newarray(); stage.addEventListener(事件输入帧、拾取项); 公共功能拾取项(e:事件) { 对于(var i=0;i您

我有一个名为“trainglePoint”的电影剪辑链接在一个带有“bgdemo”实例的movieclip中,我想知道如何让“trianglePoint”工作

此外,“gags”是将获得“三角形点”的角色

下面是我的代码,不起作用

谢谢

编辑:忘记添加“三角点”被多次放在舞台上(不知道这是否有帮助)

var pickUpsArray:Array=newarray();
stage.addEventListener(事件输入帧、拾取项);
公共功能拾取项(e:事件)
{

对于(var i=0;i您应该改用GetChildByName(name)。 GetChildAt意味着您知道所需子对象在子层中的位置。 因此,如果您的孩子名为“trianglePoint”,并且您想要访问它,只需使用getChildByName(“trianglePoint”)

代码的其余部分有几个问题。 首先,您将对象推入数组,但从不从数组中移除。使用removechild不会从数组中移除对象,这意味着您将始终测试对象是否与“gags”发生碰撞

另一个问题是在每个帧中将对象添加到数组中。您应该做的是从GetChildByName获取对象,将其推入数组中,然后循环并与之交互

我会这样做:

import flash.display.MovieClip

public class bgdemo extends MovieClip
{
var pickUpsArray:Array

public function bgdemo()//constructor for your parent movieclip
{
   pickUpsArray = new Array();

  this.addEventListener (Event.ADDED_TO_STAGE, init_ok);
  //this is to ensure the parent movieclip (bgdemo) is on the stage and we can access its children.
}

private function init_ok(e:Event):void
{
  this.removeEventListener(Event.ADDED_TO_STAGE, init_ok);
  //removing the listener so that we only do this once
  pickUpsArray.push(this.getChildByName("trianglePoint"));
  stage.addEventListener (Event.ENTER_FRAME, pickUpItems);
}

private function pickUpItems (e:Event):void
{
    for (var j=0; j<pickUpsArray.length;j++)
    {
        if (gags.hitTestObject (pickUpsArray[j]))
        {
            removeChild(pickUpsArray[j]);
            pickUpsArray.splice(j, 1); //removing the object from the array so we can't collide with it anymore
            trace ("hitTestObject: YES");
        }
    }
}

}
导入flash.display.MovieClip
公共类bgdemo扩展了MovieClip
{
var-pickUpsArray:Array
公共函数bgdemo()//父movieclip的构造函数
{
PickupArray=新数组();
this.addEventListener(Event.ADDED_至_阶段,初始_确定);
//这是为了确保父movieclip(bgdemo)在舞台上,我们可以访问它的子级。
}
私有函数init_ok(e:事件):void
{
this.removeEventListener(Event.ADDED_TO_STAGE,init_ok);
//删除侦听器以便只执行一次
pickupArray.push(this.getChildByName(“三角点”);
stage.addEventListener(事件输入帧、拾取项);
}
专用函数拾取项(e:事件):无效
{

对于(var j=0;jj为什么你不能只做gags.hitTestObject(bgdemo.trianglePoint)
?为什么你要先把它放入一个数组?因为trianglePoint被放入bgdemo多次(想象一下它就像马里奥游戏中的硬币一样)好的,问题出在哪里?是否有任何错误?是否尝试过使用日志语句进行调试?
trianglePoint
是一个特定的对象类还是一个普通的MovieClip?您的意思是如果您转到trianglePoint符号属性。您已选中了ActionScript的导出,并且在
class:
中选择了“trianglePoint”?您应该像检查
getChildAt(i)是三角形点那样检查它。键入
trace(“bgdemo.trianglePoint”)
import flash.display.MovieClip

public class bgdemo extends MovieClip
{
var pickUpsArray:Array

public function bgdemo()//constructor for your parent movieclip
{
   pickUpsArray = new Array();

  this.addEventListener (Event.ADDED_TO_STAGE, init_ok);
  //this is to ensure the parent movieclip (bgdemo) is on the stage and we can access its children.
}

private function init_ok(e:Event):void
{
  this.removeEventListener(Event.ADDED_TO_STAGE, init_ok);
  //removing the listener so that we only do this once
  pickUpsArray.push(this.getChildByName("trianglePoint"));
  stage.addEventListener (Event.ENTER_FRAME, pickUpItems);
}

private function pickUpItems (e:Event):void
{
    for (var j=0; j<pickUpsArray.length;j++)
    {
        if (gags.hitTestObject (pickUpsArray[j]))
        {
            removeChild(pickUpsArray[j]);
            pickUpsArray.splice(j, 1); //removing the object from the array so we can't collide with it anymore
            trace ("hitTestObject: YES");
        }
    }
}

}