PDA

View Full Version : Two attached MovieClips hitTesting


Hamly
12-04-2007, 05:45 PM
I have a button that will set an Interval to use a function that attachs a MC
that works fine, and so does the function. I also have it so every 5 seconds a MC will be attached for the "enemy" now I want it so lets say the one I attach and the enemies hit they will be removed. this is the code for attaching them

the one when I press the button:

function spawntank01(){
var t = attachMovie("Tank_01","tank01_"+_root.getNextHighestDepth(), getNextHighestDepth(),{_x:0,_y:435});
t.onEnterFrame = checkTankHit;
clearInterval(spawntanks01);
}
function checkTankHit(){
if(_root.wall.hitTest(this)){
wall.swapDepths(0);
wall.removeMovieClip();
}
}
and the enemies:

function spawnenemytank(){
var e = attachMovie("enetank","enetank_"+_root.getNextHighestDepth(),getNextHighestDepth() ,{_x:650,_y:435});
e.onEnterFrame = entankhit;
}
function entankhit(){
if(["tank01_"+_root.getNextHighestDepth()].hitTest(this)){
this.swapDepths(0);
this.removeMovieClip();
}
}
setInterval(spawnenemytank,5000);
If you would like more info or anything I'll give ya it, thanks.

truimagz
12-05-2007, 02:15 AM
(["tank01_"+_root.getNextHighestDepth()].

is your problem, each time you lay a tank the depth changes

tank01_"+_root.getNextHighestDepth()

does not exist

try tracing it and you'll see that

what you want to do is

function spawntank01(){

var depth:Number = _root.getNextHighestDepth()


var t = attachMovie("Tank_01","tank01_"+ depth, _root.getNextHighestDepth(),{_x:0,_y:435});

t.ID = depth

if(["tank01_"+ tank01_.ID].hitTest(this)){

arkhan
12-05-2007, 03:22 AM
or just have a variable to keep track of it.

tank01 = "";
function spawntank01(){
var t = attachMovie("Tank_01","tank01_"+_root.getNextHighestDepth(), getNextHighestDepth(),{_x:0,_y:435});
t.onEnterFrame = checkTankHit;
tank01 = t.name;//(might be t._name)
clearInterval(spawntanks01);
}

then try tracing _root[tank01] to see if its correct.

Hamly
12-05-2007, 10:08 AM
okay. Thanks truimagz and arkhan I'll try these out in a little while when I have some time.