AS2-我的影片剪辑存储在数组中,但我无法访问它们的属性或方法
我在一个数组中存储了一系列重复的影片剪辑,这样我就可以检查是否有任何子弹击中了任何敌方 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您要在库中创建剪辑的实例而不是复制已创建的对象,则似乎您需要使用
attachMovie()
而不是duplicateMovieClip
。在这种情况下,请像这样重写创建代码:It seems like you would want to use
attachMovie()
instead ofduplicateMovieClip
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:我解决了。这是因为我使用的是全局版本的duplicateMovieClio而不是类版本。再次感谢!
I solved it. It is because I was using the global version of duplicateMovieClio rather than the class version. Thanks again!