PDA

View Full Version : self tidying buttons ('snap' into place)



kidpablo
September 10th, 2003, 04:23 AM
I have a flash quiz type thing, which involves the user dragging quotes onto a choice of 2 movie clips then clicking submit to get the correct answers etc (you know the kind of thing).

My question is would it be possible to self tidy the buttons when they are dragged onto the MC's? For example quote 1 is released on the MC and it snaps straight into position 1, then when another quote is released it snaps neatly underneath into position 2 and so on....

The difficult part is that whatever qoute is dragged first, it needs to snap to the top, the second underneath, and so on...

I'd be extremely grateful if anyone can help.

Cheers.

grandsp5
September 10th, 2003, 04:38 AM
If they are all the same height its pretty easy.

var numy = 0;
if(Math.abs(quote._x - xValueToSnapTo) < snapSize) && Math.abs(quote._y - yValueToSnapTo) < snapSize)
quote._x = xvaluetoSnapto);
quote._y = topYValue + quote.height*numY;
numY++;

kidpablo
September 10th, 2003, 04:53 AM
Thanks! I kind of see what you mean, although I'm no flash wizard - so the code is a little confusing.

With this method, will it matter which quote is dragged first? Whichever is first needs to go to the top.

kidpablo
September 10th, 2003, 06:06 AM
I'm having trouble implementing this script. Would you be able to give me a hand? For example - what do I put in place of 'snapSize' ?

thanks again

grandsp5
September 10th, 2003, 03:21 PM
however many pixels you want it to snap at. For example, if its a big number, it will snap into place from relatively far away. Something around 10 should work pretty well.

kidpablo
September 11th, 2003, 12:41 AM
I still can't get it to work - below is the code i'm using.



var numy = 0;
Math.abs(Q3_PP._x - 65) < 10); && Math.abs(Q3_PP._y - 75) < 10));
Q3_PP._x = 10);
Q3_PP._y = 65 + quote.height*numY;
numY++;

grandsp5
September 11th, 2003, 01:04 AM
ill see if i can make up a fla.

grandsp5
September 11th, 2003, 01:11 AM
here is something. it has some flaws which i will try and fix later

kidpablo
September 11th, 2003, 05:56 AM
great! thanks ;)