Previvious discussion http://forums.adobe.com/message/5173983#5173983
ok this is what I got so far, four squares on the grid, respectively named: squareC1, squareC2, squareC3, squareC4. Now I want the square that we named smallSquareName to be able to fit in any of the other four, how do I tell AS3 that smallSquareName can fit in any of these squareC1, squareC2, squareC3, squareC4, at the user’s will, because as it is now smallSquareName can roam freely all over the screen (not that it is a bad thing) But just like a game of chess I want smallSquareName to move according to the guidelines of the game.
Dropping is a manual interaction involving releasing the mouse button. If you are dragging the small square, you caqn control/limit where it can go by soecifying a rectanular boundary, but it is not clear how you intend to limit the movement.
If you want to see how to implement the rectanglular boundary either look up the startDrag method in the help documentation ot search Google for "AS3 startDrag tutorial"
well the boundary is not really an issue, allow me to explain myself better. Think of it as a game of chess where you are about to move your pan from the extreme left, based on the rules of the game you can only move that pan one case(A2 move to A3 or A2 move to A4) and nowhere else, now in my case the pan is a variable called smallSquareName instead of two possibilities it has four: squareC1, squareC2, squareC3, squareC4, in other words when I or the user do a mouse click on smallSquareName move it over then release it I want only four possible drop spot for it to fit squareC1, squareC2, squareC3, squareC4. I want to know how can I write such code in AS3?
put your 4 targetsquares in an Array
then upon releasing the mouse (stopDrag),
check if the "PAWN" collides with any of these 4 squares
with hitTestObject, and if so
Tween it to the position of this square
Tween it back to the place where the player started his dragging
You need to make your game intelligent enough to know what targets are valid ones for any movement of the small square. As the oher response indicates, you could place all the legitimate targets into an array an check if that array contains the drop target when the drop occurs, and if so, align the small square to that drop target.
well I think I understand the logic in that ,however I'm not sure that I know how to accomplish it, first of all I think that I got the Array correct, however when I try to use the hitTestObject mentioned I’m getting all sort of error, so I was thinking if it’s ok for me to send you (or anyone willing to help)my files so that you can help me correct the mistakes. My aim is to make the red square fit into any of the bleu.
here is the file http://www9.zippyshare.com/v/76591404/file.html
No offense, but at this time you have shown no line of actual code you have written, nor a screenshot of a mockup you made.
This is a repeating patterrn, obviously, because the last thread you made (and linked to in the first post) didn`t show anything you have written, too.
I doubt anyone will fix your files for you.
when I try to use the hitTestObject mentioned I’m getting all sort of error
Show the errors, and show the code that is triggering them