7 Replies Latest reply on Apr 16, 2008 7:37 AM by Mr.Wallace

    Hitting multiple targets...

    Mr.Wallace Level 1
      Hey all!

      So, here's my current situation...

      I've created a movie that has numerous drop targets and actions that take place when they are hit. Everything is working beautifully! I would like to take it a step further however.

      I was wondering if it's possible to have an action take place after a certain amount of targets have been hit?

      For example:

      - I have 5 targets called T1, T2, T3, T4, T5
      - I have 3 objects that get dropped onto those targets called O1, O2, O3
      - only T1, T2, T3 are active targets, meaning, if O1 gets dragged onto T1 then that is correct...same with O2 onto T2 and O3 onto T3
      - if O1, O2, O3 get dragged and dropped onto any other target(s), the object justs returns back to where it started from, if the drag and drop is correct, the objects stays on that target
      - once T1, T2, and T3 have been hit, I want an action to happen (for example, a button shows up saying 'CORRECT! Click here to go to next level.')

      Is it possible? Only when all the correct targets have been hit will this action take place.

      Anybody up to the challenge?

      Thanks for your time,

      Mr. Wallace
        • 1. Re: Hitting multiple targets...
          FlashTastic Level 1
          All you need to do is create a little counter.

          • 2. Re: Hitting multiple targets...
            Mr.Wallace Level 1
            Excuse my ignorance...

            Do I put that code on the movie clip/object, the drop target, or on the frame in the main timeline?
            • 3. Re: Hitting multiple targets...
              FlashTastic Level 1
              Where is the majority of your code?

              Normally most code in a movie should be contained on the main timeline, but if you have code on your movieclips then this presents a slightly different challenge as the clips need to be able to look at the count variable.

              You stated that you already have the following functionality:

              When an 0 clip hits a T clip and it is incorrect, it snaps back to the original position. When an 0 clip hits a T clip and it's correct, it stays.

              Wherever the code is located that handles that logic is where you want to insert this counter check.

              Try using a global variable instead:

              _global.numCorrect = 0;

              if(_global.numCorrect == 3) ... etc.

              If you're still having trouble, post some code.

              • 4. Hitting multiple targets...
                Mr.Wallace Level 1
                Ok, that makes sense...

                Re-reading my explaination, I see I didn't say everything I needed to. This is what I have...

                There are a lot of targets/drop zones that are all copies of the same movie clip with different instance names (eg. T1). That movie clip has a few frames within it that contain different information. Once, let's say O1 is dragged onto T1, O1 snaps back to its original place regardless because it is used again to trigger some of the other targets. So, once it hits T1, my code tells O1 to go back to it's place and tells the T1 target to GoToandPlay a certain frame number. Then O1 can be used again to trigger, say, T3 as well.

                In my code, "A" takes the place of "O1". Here's the code I'm using within the objects (eg. O1):

                • 5. Re: Hitting multiple targets...
                  FlashTastic Level 1
                  You have two ways of making this work - the easy way and the long, lots of typing way.

                  The long, lots of typing way (which will make more sense to you) is this:

                  On your _root timeline add:

                  _global.numCorrect = 0;

                  Then (try it on a couple of clips before changing your entire program), change your code to

                  if (_root.A._droptarget == "/T54") {

                  if(numCorrect == 3){
                  //do your congratulations or whatever.

                  I've attached a heavily commented code sample for you to look at if you're interested in a nicer, easier to maintain solution.

                  If you're still having trouble, post an .fla somewhere.

                  • 6. Re: Hitting multiple targets...
                    Mr.Wallace Level 1
                    Wow, ok...I'm gonna have to take some time with this. I will work through your code and try my best to apply it.

                    If I have any problems or questions I will send you a message.

                    Thank you so much for your time and effort!!!
                    • 7. Re: Hitting multiple targets...
                      Mr.Wallace Level 1
                      Hey Flash, do you think it would be easier to create a button (eg. a SUBMIT button) and attach code to it saying that, when all targets have been hit, when it is pushed it will say something like YOU'RE NOT DONE YET / INCORRECT (if the targets haven't been hit) or CORRECT (when they are hit) and then goes to a congratulations screen or something like that?