Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using more then 1 .as class

Participant ,
May 26, 2013 May 26, 2013

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

TOPICS
ActionScript
723
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 26, 2013 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--){

Translate
Community Expert ,
May 26, 2013 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)){

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 26, 2013 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2013 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--){

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 26, 2013 May 26, 2013

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2013 May 26, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines