Copy link to clipboard
Copied
This is probaly a really simple question but here we go.
My enemy is made up of 20 different Movieclips. Part1, Part2 ect
I have a class which bacicly has this in: if(this.hitTestObject(BulletArray)) //Do something (RemoveChild Probaly)
All the code works all I want to know is how to apply the .as class to all 20 parts of the enemy, Previosly I just had 20 .as classes but I knew that was very imparcticle when I need to change things so I want to apply the .as class to the 20 parts how could I go about doing this.
Thanks
yes, using an array would be one way to loop through each movieclip. assign each an instance name and use that in your array:
var partsA:Array=[head, nectk,armLeft,armRight,...];
for(var i:int=partsA.length-1;i>=0;i--){
Copy link to clipboard
Copied
if your enemy class instances have 20 children and you want to hittest against the children use something like:
if(this.armLeft.hitTestObject(BulletArray)){
or, if the only children for your enemy class instances are the 20 different movieclips, you can use:
for(var j:int=this.numChildren-1;j>=0;j--){
if(this.getChildAt(j).hitTestObject(BulletArray)){
Copy link to clipboard
Copied
I was thinking that but I have other children in my enemy and I dont want them removed
Maybe put all the 20 children in an array and test hitest against it?
How would I go about doing this, Instance name them then add them with .push or have a for loop adding all children to the array then check the array and take out the ones I don't need?
Copy link to clipboard
Copied
yes, using an array would be one way to loop through each movieclip. assign each an instance name and use that in your array:
var partsA:Array=[head, nectk,armLeft,armRight,...];
for(var i:int=partsA.length-1;i>=0;i--){
Copy link to clipboard
Copied
Thanks
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now