Okay, so there was some confusion with my last post, and my improper use of terminology. So here goes again.
Is there a way to make a hitTest for any existing movie clip without knowing the name of it in advance?
For instance, if I have a bullet and I want to see if it hits either a target(whose name is target1 through 20, a sandbag(1 through 10) or a friendly(1 through 5). Is there a code I can put in so that if the bullet hits ANY clip, it brings back the name of the clip so I know what it hit?
Something along these lines would work (haven't tested it, but i think youll get the idea...
Code:
//where 'mymovieclipstotal= your total mcs that u want to target
//store the mc names in an array 'mymcs'
//of course it can be an onmovelistener instead with the same idea
square_mc.onPress = function() {
this.startDrag();
};
square_mc.onRelease = function() {
this.stopDrag();
for (q=0;q<mymovieclipstotal;q++){
nameit=mymcs[q];
if (this.hitTest(_root[nameit])) {
trace("you hit an mc");
//smthn more here possible
//ex. if _root[nameit].whattype=="friendly"
//above: if you made whattype an attribute with class
}
}
};
I get your drift there. Is there a way to get multiple different strings in one variable? like if i want sandbag, target and friendly, each with multiple duplicates, in a string called this_hit.
add a comma (or any character you are sure you wont use) between each value and and add it to the var, and then use the string split (see help file example with the "," case- automatically puts it back into an array of strings again for u
How will splitting the string help me accomplish what I need unless everything is in the string?
Is there a way to add the length of an array by nominating the index is a variable? Example when I duplicate my clips, i do dupe++; I've tried doing myarray[dupe]="target"+dupe;
but it just deosn't seem to work. Is there something wrong in the code, or is it just not doable that way?
How will splitting the string help me accomplish what I need unless everything is in the string?
Is there a way to add the length of an array by nominating the index is a variable? Example when I duplicate my clips, i do dupe++; I've tried doing myarray[dupe]="target"+dupe;
but it just deosn't seem to work. Is there something wrong in the code, or is it just not doable that way?
That's basically it lol.
My code is relatively the same, but deosn't seem to work. What do however is I have one of my incrementations on the push of a button, so i do array[_root.hero.dupe]=this._name; this code being in the new item created. Can i call the function like that, or did I just muff something up?
when you call a dynamic name for a movie clip then instead of
_root.hero.dupe you need to do _root.hero[dupe]... but thats for referring to a movie clip... can u post your code with some comments in it to understand what you are trying to do please
bullet.onEnterFrame = function () {
for (i in this._parent) {
if (this.hitTest(_this._parent[i]) && (i._name.substr(0,6) == target || i._name.substr(0,6) == sandba || i._name.substr(0,6) == friend)) {
trace("bullet has hit : " + i);
}
}
You should be able to figure out how to make it cleaner once you get it working.