6 Replies Latest reply on Jun 8, 2006 7:36 AM by Brandine

    Array confusion


      I have a problem with my array function, moveover, I don't understand why this is not working. I am defining 2 arrays in the code below and performing a hitTest to try and detect which object in the clip2 array that clip1 is actually hitting, when the hitTest is performed, the trace output traces out all 33 items instead of the specific item. If any1 could help me to understand what i am doing wrong, I would be very thankful.

      Thanks for looking at my post,
        • 1. Re: Array confusion
          blemmo Level 1
          I think there's something wrong with the logic in this code: it does a hittest for wk_array[1] and my_array[1], then for wk_array[2] and my_array[2] and so on. If the objects with matching numbers overlap, every hittest returns true and it will trace all 32 clips.
          I guess you wanted to do a hittest of 1 object from array 1 with all objects of array 2, so you should define clip1 before the loop starts, like in the attached code. If you wanted something else, please explain in more detail.


          • 2. Re: Array confusion
            Brandine Level 1
            hey blemmo,

            Thx for the response. That still didn't sort my problem out, I will try to provide more detail. Here's the goal:

            I have a grid built on the stage, made up of 32 squares, represented by wk_array(clip1). I also have 32 draggable pieces, represented by my_array(clip2). When I let go of one of the draggable pieces, I want to be able to trace back the individual square that the individual piece is hitting. This is not the way to do it: :)

            //perform hitTest
            for (i:Number = 1; i < 33; i++) {
            clip1=eval(wk_array[ i ]);
            clip2=eval(my_array[ i ]);

            This traces back the entire list, and I agree with you, something is wroing with the logic. I am struggling to understand how this logic works. Thanks for any help.

            • 3. Re: Array confusion
              2m Level 2
              take a look at "MovieClip._droptarget" in the docs should help - if not for some reason I'll take acloser look at the script. OK?
              • 4. Re: Array confusion
                blemmo Level 1
                Good point with the _droptarget property, this might work out quite easy.

                Although I see a little problem with finding the right MC... As I understand, the targets are right next to each other, so in case the dragged clip isn't dropped exactly over a square, it will also hit the neighbor squares. I wonder if _droptarget takes that into account and returns the target that has the biggest area of intersection... otherwise, it might be necessary to compare the coordinates manually.
                • 5. Re: Array confusion
                  2m Level 2
                  I havent used it in a long time but if I remember it corectly it should give you the clip that is under your mouse - would be the logical thing to do at least and it would almost certainly "feel" right this way.

                  It does behave that way, the only ploblem is, if you drag the floating item at its corner, drag it 90% over the target-clip, but the mouse isn't over the clip it won't work - but then you might have a hard time with any other solution.
                  Draging the object by the center only will help, but to make it real usable a visual feedback (highlightnig) before dropping would really be useful I guess.
                  • 6. Re: Array confusion
                    Brandine Level 1
                    !w000t! Thx guys for the replies. _droptraget did the trick. Like you guys mentioned in the later posts, I'll have to finesse it a bit. I ended up putting the code on the actual mc(piece to be moved), added a bit more code, and now it's working perfectly. Thanks again guys,


                    p.s. - The code below sorted me out