2 Replies Latest reply on Oct 16, 2009 12:10 PM by Synaptrik

    Finding an object at x, y


      Hello all,


      We have a client server architecture where a C++ server talks to Flash clients. I'm developing the server and would like to send through tcp an xy coord to simulate a button press where the receiving flash client would find the topmost visible object at that coord and send a mouse event to it such that we could simulate play without a human present.


      I'm told this is incredibly difficult, but it seems to me that there must be a way to do this without too much pain.


      Am I off the mark? Or is there a mechanism in flash to iterate through all objects regardless of parent child relationships to find a visible button at an x, y coord and signal a press event?


      Thanks in advance for any help.



        • 1. Re: Finding an object at x, y
          RossRitchey Level 4

          The function getObjectsUnderPoint in AS3 will give you an Array of all objects under the point you pass in.




          var obj:Array = getObjectsUnderPoint(new Point(5,5));


          This will give you all objects under the point 5,5.


          I haven't used this, so I don't know what the order of the objects in the Array is.  Likely, the first object in the array ( [0] ) will be the top-most, but you will have to test to be certain.


          From there, its a matter of telling that object to dispatch an event:


          obj[0].dispatchEvent(new MouseEvent(MouseEvent.CLICK));

          • 2. Re: Finding an object at x, y
            Synaptrik Level 1

            Thanks! I'll give this a try.