Hitting Enemy (Flash AS3)

67 views Asked by At

My Hero and Enemy movieclips are nested inside a map movieclip.

The Hero adds another moveclip like this:

parent.addChild(_Punch);
_Punch.x = this.x;
_Punch.y = this.y;

The Map Movieclip that contains both the Hero and the Enemy is where the _punch is being added. The Enemy has the instance name of "Sheep" How then, do I access the punch? Do I do this inside the punches Class File? My main question is that I do not know how to access the punch.

1

There are 1 answers

0
Jawad Khan On

It depends how you write your logic and how you place your objects.

You can always access Movieclips with their instance names. If a MovieClip is inside the parent movieclip then you will write as follows:

MovieClip(parent).movieclip_instance_name.x = ..

To access the child of the same MC, you will do as follows:

MovieClip(parent).movieclip_instance_name.child.x ...

Also, to check collision you would use HitTestObject or HitTest ideally inside the ENTER_FRAME event.

Again all depends upon your scenario and your own logic of doing the same.

Cheers