how do you hitTest for a duplicated mc?
I've tried
if (this.hitTest (_root.dupedmc[i])) {
trace("please work this time";
}
am I doing something wrong, or is my flash program just messed up?
Printable View
how do you hitTest for a duplicated mc?
I've tried
if (this.hitTest (_root.dupedmc[i])) {
trace("please work this time";
}
am I doing something wrong, or is my flash program just messed up?
are you storing a reference to every duplicated MC in an array? and/or are you adding them to a specific movieclip, like "enemies"?
You forgot a ) to close your trace, maybe that's it? Because if dupedmc[i] is in fact a reference to a valid movieclip (duplicated or not, shouldn't matter), it should work.
Try tracing dupedmc[i] and see what you get.
I use this to duplicate it:
blahblahblah.onEnterFrame =...
...
dupedmc.duplicateMovieClip( "dupedmc"+i, i++ );
fixed the trace, still nothing.
_root["dupedmc"+i]
I though you could only use that when you store the referance of a MC in an array. I Must be wrong?Quote:
_root["dupedmc"+i]
code:
_root["dupedmc"+i]
^ this means you'll target things like:
_root.dupedmc1
_root.dupedmc2
_root.dupedmc3
_root.dupedmc4
...etc
code:
_root.dupedmc[i]
^ this means you'll target things like:
_root.dupedmc.MC1
_root.dupedmc.MC2
_root.dupedmc.MC3
_root.dupedmc.MC4
...etc
ANYWAY, did you specify anything for "i" when you perform your hitTest? a for loop in your case...
nothing continues to work with this. Here is virtually the exact code I'm using to duplicate and check for a hitTest:
bob.onEnterFrame = function() {
if (bob.hitTest (_root["dupedmc"+i])) {
trace("yes");
}
duplicateMovieClip(_root.dupedmc, "dupedmc" + i, i++);
}
at this point, I'm starting to assume there's just something wrong with my program.
btw, I've got other code set up to where it doesn't duplicate on EVERY frame, only on some, I just opted not to show that.
it would be helpful if you try to explain what exactly happens. "nothing continues to work with this" is no propper explanation of the problem.Quote:
Originally Posted by Captain_404
On first glance i see several reasons for it still not working:
1.: Did you initialize the variable i with 0 value ahead?
2.:
duplicateMovieClip(_root.dupedmc, "dupedmc" + i, i++);
where do you count i up? Just for the depth or somewhere else in your enterframe?
3.:To check hittest with several instances you need to iterate through em with a loop,as you do it now:
if (bob.hitTest (_root["dupedmc"+i])) {
you only check for hit with one instance
404, did you even check your OUTPUT window when you publish?
Any errors?
@Ray Beez
I check the output box every time, nothing.
@tomsamson
1. yes
2. just for the depth, should I be doing it differently? I tried changing it to: depth = 1+1000 and then i++ on the next line with no affect
3. ?...this is where you lost me, so that's probably my problem...
2. if you increment something within duplicateMovieClip it doesn't do that globaly so change that to outside, see code below...Quote:
Originally Posted by Captain_404
3. if you do not have a for loop you are checking collision only between bob and a single i value.
I hope this will work for ya:
PS: I understand that you guys want this guy to stuggle but I think the servers would be thankfull if you cleared questions sooner :p and not bit by bit. But I guess its a win-lose sitiuation.Code:bob.onEnterFrame = function() {
for (var n = 0; n<i; n++){
if (bob.hitTest (_root["dupedmc"+n])) {
trace("yes");
}
duplicateMovieClip(_root.dupedmc, "dupedmc" + i, i);
i++;
}
}
guys, you've helped me a lot too!!! sometimes it surprises me-why i can't get it out myself?