Skip to main content
Inspiring
May 26, 2013
Answered

Using more then 1 .as class

  • May 26, 2013
  • 1 reply
  • 792 views

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

This topic has been closed for replies.
Correct answer kglad

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--){

1 reply

kglad
Community Expert
Community Expert
May 26, 2013

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)){

Inspiring
May 26, 2013

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?

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 26, 2013

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--){