AS2-我的影片剪辑存储在数组中,但我无法访问它们的属性或方法

发布于 2025-01-07 13:37:07 字数 1109 浏览 2 评论 0原文

我在一个数组中存储了一系列重复的影片剪辑,这样我就可以检查是否有任何子弹击中了任何敌方 MC。但是,Flash 不允许我访问影片剪辑上的属性或方法。

function checkHits(){//checks for hits between enemies and bullets
for (var zz = 0; zz < bulletArray.length; zz += 1)//checks for each bullet
{
for(var yy=0;yy<enemiesArray.length;yy+=1){//checks for each enemy
    trace("enemies loc"+yy+":"+enemiesArray[yy]);
    trace("bullet loc"+zz+":"+bulletArray[zz]);
    if(bulletArray[zz].hitTest(enemiesArray[yy])){
        trace("HIT!");
       removeMovieClip(bulletArray[zz]);
       removeMovieClip(enemiesArray[yy]);
       bulletArray.splice(zz,1);
       enemiesArray.splice(yy,1);
       }//end if
}//end for
 }//end for

这就是代码,它会在每一帧运行并检查是否有任何东西命中。 hitTest 永远不会注册,但如果我更改 hitTest 对象,removeMovieClip 就会起作用。所以我可以成功引用该对象,但无法访问任何属性。如果我尝试,它们总是会出现未定义的情况。

作为参考,这里是项目符号生成的代码。请注意,这两个函数都是根级函数。

function dupeCircle()
{
//trace("Dupe circle initiated");
duplicateMovieClip(circlebase, "circle" + circleCount, circleCount);
bulletArray.push("circle" + circleCount);
trace(bulletArray[0]._width);
circleCount += 1;
}

I have stored a series of duplicated movieclips in an array, so that I can check to see if any of the bullets are hitting any of the enemy MCs. However, Flash will not let me access the properties or methods ON the movieclips.

function checkHits(){//checks for hits between enemies and bullets
for (var zz = 0; zz < bulletArray.length; zz += 1)//checks for each bullet
{
for(var yy=0;yy<enemiesArray.length;yy+=1){//checks for each enemy
    trace("enemies loc"+yy+":"+enemiesArray[yy]);
    trace("bullet loc"+zz+":"+bulletArray[zz]);
    if(bulletArray[zz].hitTest(enemiesArray[yy])){
        trace("HIT!");
       removeMovieClip(bulletArray[zz]);
       removeMovieClip(enemiesArray[yy]);
       bulletArray.splice(zz,1);
       enemiesArray.splice(yy,1);
       }//end if
}//end for
 }//end for

That is the code, which runs ever frame and checks to see if anythign is hitting. The hitTest never registers, but if I change the hitTest objects, the removeMovieClip does work. So I can reference the object successfully, but I cannot access any properties. If I try, they always come up undefined.

For reference, here is the code for the bullet generation. Note that both these functions are root-level functions.

function dupeCircle()
{
//trace("Dupe circle initiated");
duplicateMovieClip(circlebase, "circle" + circleCount, circleCount);
bulletArray.push("circle" + circleCount);
trace(bulletArray[0]._width);
circleCount += 1;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九命猫 2025-01-14 13:37:08

如果您要在库中创建剪辑的实例而不是复制已创建的对象,则似乎您需要使用 attachMovie() 而不是 duplicateMovieClip。在这种情况下,请像这样重写创建代码:

_root.attachMovie(circlebase, "circle" + circleCount, circleCount);
bulletArray.push(_root["circle"+circleCount]);

It seems like you would want to use attachMovie() instead of duplicateMovieClip if you are creating an instance of the clip in the library rather than copying an already-created object. In which case, rewrite the creation code like this:

_root.attachMovie(circlebase, "circle" + circleCount, circleCount);
bulletArray.push(_root["circle"+circleCount]);
残月升风 2025-01-14 13:37:08

我解决了。这是因为我使用的是全局版本的duplicateMovieClio而不是类版本。再次感谢!

I solved it. It is because I was using the global version of duplicateMovieClio rather than the class version. Thanks again!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文