Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 10-28-2007, 04:05 AM   #1
Phenius
Registered User
 
Join Date: Oct 2007
Posts: 35
Default [AS2] hitTesting many clips?

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?
Phenius is offline   Reply With Quote
Old 10-28-2007, 10:30 AM   #2
Scott Euser
Registered User
 
Join Date: Oct 2007
Posts: 186
Default

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
       }
    }
};
hope that helps!
Scott Euser is offline   Reply With Quote
Old 10-28-2007, 03:38 PM   #3
Phenius
Registered User
 
Join Date: Oct 2007
Posts: 35
Default

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.
Phenius is offline   Reply With Quote
Old 10-28-2007, 07:54 PM   #4
Scott Euser
Registered User
 
Join Date: Oct 2007
Posts: 186
Default

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
Scott Euser is offline   Reply With Quote
Old 10-29-2007, 01:26 AM   #5
Phenius
Registered User
 
Join Date: Oct 2007
Posts: 35
Default

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?
Phenius is offline   Reply With Quote
Old 10-29-2007, 06:05 AM   #6
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

I'm not sure what you are trying to do with the dupe. Are you aware of functions such as myarray.push(__) or myarray.unshift(__) ?
rrh is offline   Reply With Quote
Old 10-29-2007, 07:27 AM   #7
Scott Euser
Registered User
 
Join Date: Oct 2007
Posts: 186
Default

Quote:
Originally Posted by Phenius View Post
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?
like this u mean?

Code:
myarray=[];
dupe=0;
myarray[dupe]="hi1";
dupe++;
myarray[dupe]="hi2";
trace(myarray[0]);//outputs hi1
trace(myarray[1]);//outputs hi2
but what is your purpose there? ahh i see... you want to pass dupe to that function and you will do a

Code:
trace("you just shot a "+myarray[dupe]); //with the values in the array as fiendly, etc
Scott Euser is offline   Reply With Quote
Old 10-29-2007, 02:47 PM   #8
Phenius
Registered User
 
Join Date: Oct 2007
Posts: 35
Default

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?
Phenius is offline   Reply With Quote
Old 10-29-2007, 03:15 PM   #9
Scott Euser
Registered User
 
Join Date: Oct 2007
Posts: 186
Default

sorry, thats muffed 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

thx
Scott Euser is offline   Reply With Quote
Old 10-29-2007, 03:42 PM   #10
MonkeyBiscuits
King of the Monkeys
 
Join Date: Oct 2004
Location: com.utils.house
Posts: 319
Post

It's a bit dirty, but this should do the trick:

Code:
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.
MonkeyBiscuits is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to initiate an action when movie clips finish playing Angel2727 ActionScript 2.0 2 05-26-2008 08:19 AM
Movie clips that won't act like buttons! guytrenzich ActionScript 2.0 6 06-24-2007 09:39 PM
problem with child clips in main clip whiteboxer ActionScript 2.0 1 11-09-2006 05:45 PM
How can I load multiple movie clips and mp3 so that the swf file will work? wlester ActionScript 2.0 0 09-16-2005 09:01 AM
Movie Clips Order Luigi Vercotti ActionScript 1.0 (and below) 2 02-27-2004 10:32 AM


All times are GMT. The time now is 09:05 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.