In this statement
var newtarget:enemy=new enemy();
var
- keyword used to define varibles, newtarget
- variable name in which pointer to new class instance stored, :enemy
- data type (the class name), new
- keyword used to create new class instances, and finally enemy
is class constructor (by the way there is a rule of good manners by which class names are capitalized)
So answer for you question which should you use when you want check is some is overlapping is 'newtarget'.
Now about hit test - all you need do to check if two objects hit each other is correctly use their references from the part of project where your code is writen.
For example if you have your fire_mc
on MainTimeline created by IDE, and code of creation of you enemy
instance stored in newtarget
sameplace, then if you check will be placed in frame of MainTimeline where both object present it will be like this
fire_mc.hitTestObject(newtarget);
or this
newtarget.hitTestObject(fire_mc);
All these statements give you same result - if objects intersect each other you have true
returned.
If you created 'newtarget' on MainTimeline and checks will be from fire_mc
(which is on MainTimeline to) frame, then code will something like that
this.hitTestObject(MovieClip(root).newtarget);
Now about root
. Primarily it is a property of DisplayObject
in which reference to the top-most display object in swf-file structure is stored. So as such it is inherited by all child classes. So here's the trick. When you try get your objects in swf structure using root here the differences are based on the fact that root
always return object as DisplayObject
and that means what if you object contains something that DisplayObject
shouldn't you can't get it. So you must convert returned reference to need data-type usign MovieClip(...)
.