A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: simple question, simple answer

  1. #1
    file not found Captain_404's Avatar
    Join Date
    Apr 2006
    Posts
    457

    simple question, simple answer

    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?

  2. #2
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    are you storing a reference to every duplicated MC in an array? and/or are you adding them to a specific movieclip, like "enemies"?
    lather yourself up with soap - soap arcade

  3. #3
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    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.

  4. #4
    file not found Captain_404's Avatar
    Join Date
    Apr 2006
    Posts
    457
    I use this to duplicate it:
    blahblahblah.onEnterFrame =...
    ...
    dupedmc.duplicateMovieClip( "dupedmc"+i, i++ );



    fixed the trace, still nothing.

  5. #5
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793
    _root["dupedmc"+i]

  6. #6
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874
    _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?
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

  7. #7
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    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...

  8. #8
    file not found Captain_404's Avatar
    Join Date
    Apr 2006
    Posts
    457
    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.

  9. #9
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    Quote Originally Posted by Captain_404
    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.
    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

  10. #10
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793
    404, did you even check your OUTPUT window when you publish?

    Any errors?

  11. #11
    file not found Captain_404's Avatar
    Join Date
    Apr 2006
    Posts
    457
    @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...

  12. #12
    CostomJunky Xploder's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    635
    Quote Originally Posted by Captain_404
    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...
    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:
    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++;
        }
    }
    PS: I understand that you guys want this guy to stuggle but I think the servers would be thankfull if you cleared questions sooner and not bit by bit. But I guess its a win-lose sitiuation.
    Last edited by Xploder; 08-29-2006 at 07:39 PM.

  13. #13
    Member
    Join Date
    Aug 2006
    Posts
    33
    guys, you've helped me a lot too!!! sometimes it surprises me-why i can't get it out myself?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center