
Welcome Guest
|
|
|
#1
|
|||
|
|||
|
i need a flash4 script that lets me drag a m/clip horizontally but after i drop it, i need the clip to keep moving until it gradually slows down and stops.
any takers? |
|
#2
|
||||
|
||||
|
Try this
After you have dropped the draggable clip,
Tell the host movie to go to next frame where you get the position of the dragged MC and then in the next frames add or subtract values to it the x decreasing amounts. and finally put a stop at the final frame. E.G PART 1 YOUR DRAGGABLE CLIP AND THE BUTTON INSIDE IT: On (Press) Start Drag ("/YOURMC", L=100, T=160, R=390, B=160) End On On (Release, Release Outside) If (GetProperty ("/yourmc", _droptarget ) eq "/your target") Go to and Play (2) End If Stop Drag End On That ended the draging and is now going to frame 2 where you may have something like this: Begin Tell Target ("/yourmc") Set Property ("yourmc", X Position) = +50 End Tell Target now frame 3: Begin Tell Target ("/yourmc") Set Property ("yourmc", X Position) = +25 End Tell Target frame 4: Begin Tell Target ("/yourmc") Set Property ("yourmc", X Position) = +10 End Tell Target and 5: Begin Tell Target ("/yourmc") Set Property ("yourmc", X Position) = +5 End Tell Target frame 6 should now have a 'stop' in it so that it does not loop. Hope this helps in some small way!
__________________
If there was only one heaven I would not want to go! |
|
#3
|
|||
|
|||
|
cheers for that.
and yeah, it's a pretty simple solution. but what if i wanted the clip to move (after i drop it) in the same direction as i'd just dragged it (horozontally only - either left or right). and then make the 'aftermove' proportional to the distance i'd just dragged it. i'd need to register the xpositions of the movie clip before and after dragging, calculate the difference, then tell the movie clip to move the difference/2(say) repeatedly until that value reaches as close to zero as possible. so if i drag the clip 100 pixels and drop it, the next frame it will move 50 pixels, the next frame it will move 25 pixels, the next 12.5 pixels, and so on until it stops. but what if i drag the clip and pause between stopping any mouse movent and releasing the drag button? that'll just look plain odd, won't it. and then, if i drag it one way 100 pixels then drag it the other way 50 pixels and *then* drop it, the clip would move the opposite way i'd *just* dragged it. hmm. |
|
#4
|
||||
|
||||
|
Hello again,
I suggest you post this in the actionscript forum and be sure to tell the guys that your working with flash 4. You may want to visit actionscript.org since they have lots of examples with downloadable source. In the meanwhile, goodluck. If i find anything i'll let you know.
__________________
If there was only one heaven I would not want to go! |
|
#5
|
|||
|
|||
|
Actually....i found something very similar yesterday...just trying to figure out how to adapt it to what i want.
Cheers. |
|
#6
|
||||
|
||||
|
Hi, I felt like having a go at this so:
[swf x="300" y="300"]http://www.cleverpig.com/tutorials/continuedrag.swf[/swf] I've done it for both X and Y since that's more general, and I've also added a bounce to the clip (anticipating questions later) but if you only want horizontal drag - simply ignore all the Y coding. ...I'm afraid I only have Flash 5 so the source file will not be any use. Here it is anyway for any Flash 5 users. Get the Flash 5 FLA ...however, since the question was about how to do this in Flash 4 I avoided doing anything that couldn't be done with 4 so here's an explanation. The scene contains a single MC inside the MC is a button positioned at the origin - the button has a radius of 10. The MC has two frames. The script in the second frame is simply gotoAndPlay(1); - the first frame I will come to in a moment since that's where the bulk of the script is. The button has a basic drag script allowing the mc to be dragged inside the window (but not outside). In addition it sets a variable 'dragging' to true or false depending on whether the MC is currently being dragged. Here's the script in Flash 5 syntax: Code:
on (press) {
dragging = true;
startDrag ("", true, 10, 10, 290, 290);
}
on (release, releaseOutside) {
stopDrag ();
dragging = false;
}
...take a deep breath, here comes the script(Flash 5 syntax but compatible with 4) Code:
damping = 0.95;
if (dragging) {
newX = getProperty("", _x);
newY = getProperty("", _y);
deltaX = newX-lastX;
deltay = newY-lastY;
lastX = newX;
lastY = newY;
} else {
newX = getProperty("", _x)+deltaX;
newY = getProperty("", _y)+deltaY;
if ((newX>289) or (newX<10)) {
deltaX = -deltaX;
newX = deltaX+newX;
}
if ((newy>289) or (newy<10)) {
deltaY = -deltaY;
newY = deltaY+newY;
}
setProperty ("", _x, newX);
setProperty ("", _y, newY);
deltaX = deltaX * damping;
deltaY = deltaY * damping;
}The part after if (dragging){ keeps track of the change in X & Y. Step by step it:[list=a][*]gets the current position (newX=getProperty....)[*]calculates the change in position by subtracting the position at the last frame from the current position (deltaX = newX - lastX)[*]sets the new value for the last position ready for the next time the code is executed (lastX = newX)[/list=a] the part after the else is where the magic happens. At the point that you drop the clip it takes over and adds the last known speed (deltaX, deltaY) to the current position... newX = getProperty("",_x) + deltaX; and then checks to see if the clip has gone 'out of bounds' if ( (newX <10) or (newX > 290) ) { (same for Y of course) if it has gone too far - the sign of deltaX (or Y) is flipped by negating it (deltaX = -deltaX) and then it is added back to the current position to bring the clip back into the frame, but now travelling in the opposite direction. The actual position of the clip is then updated using the calculated value... setProperty( "",_x, newX); finally the amount of motion is decreased ready for the next time the script is executed by multiplying the deltaX & Y values by the value of damping... because both are decreased by the same proportion, the clip will hold its direction while slowing down (try decreasing them by different factors to see what happens!) I hope this has been of help, hopefully the syntax is only slightly different & you can duplicate this in Flash 4. If you do - maybe you would post it here for all those other people still using 4 ...
__________________
CleverPig : Non plaudite. Modo pecuniam jacite
|
|
#7
|
|||
|
|||
|
Excellent work Cleverpig
![]() Can I amend that FLA as a full tut' for the source page I'm starting ? http://sitetest4.tripod.com/fla/index.htm ~Av~ |
|
#8
|
||||
|
||||
|
sure... but there's no commenting inside there so you probably want to paste the explanation as well...
please give credit tho... |
|
#9
|
||||
|
||||
|
since we're playing around with this stuff... how about this one (modifying the code a little...)
[swf x="300" y="300"]http://www.cleverpig.com/tutorials/moredrag.swf[/swf] ...spot the changes... Code:
damping = 0.99;
friction = 0.8;
gravity = 2;
if (dragging) {
newX = getProperty("", _x);
newY = getProperty("", _y);
deltaX = newX-lastX;
deltay = newY-lastY;
lastX = newX;
lastY = newY;
} else {
newX = getProperty("", _x)+deltaX;
newY = getProperty("", _y)+deltaY;
if ((newX>289) or (newX<10)) {
deltaX = -deltaX;
newX = deltaX+newX;
deltaX = deltaX* friction;
deltaY = deltaY* friction;
}
if ((newy>289) or (newy<10)) {
deltaY = -deltaY;
newY = deltaY+newY;
deltaY = deltaY* friction;
deltaX = deltaX* friction;
}
setProperty ("", _x, newX);
setProperty ("", _y, newY);
deltaX = deltaX * damping;
deltaY = (deltaY+gravity) * damping;
} |
|
#10
|
||||
|
||||
|
...hey, wierd bug in my code... try putting the mc right up against the right hand edge!
|
|
#12
|
||||
|
||||
|
...its a feature
...OK!-I think I've just discovered a unique property of Flash browser windows... gravity is stronger in the bottom right corner ![]() -dumbpig |
|
#13
|
||||
|
||||
|
...get them all bouncing at once...
-ok last one before I get smacked for putting too many movies in a thread
(this is all still Flash 4 compatable by the way)[swf x="300" y="300"]http://www.cleverpig.com/tutorials/yetmoredrag.swf[/swf] -I was stupid... the drag area didn't match the point at which the bounce takes place so effectively you were able to sneak past a 1 pixel hole at the right edge of the window... the bounce tests ought to read: Code:
if ((newX>290) or (newX<10)) {
deltaX = -deltaX;
newX = deltaX+newX;
deltaX = deltaX* friction;
deltaY = deltaY* friction;
}
if ((newy>290) or (newy<10)) {
deltaY = -deltaY;
newY = deltaY+newY;
deltaY = deltaY* friction;
deltaX = deltaX* friction;
}
__________________
CleverPig : Non plaudite. Modo pecuniam jacite
|
|
#14
|
||||
|
||||
|
good job.
![]() but i noticed that the ball bounces up before it touches the ground sometimes. i dunno if it's the frame rate problem or my eye playing tricks. Or perhaps it could be you need to calculate the radius of the ball into it too?
__________________
Twitter . |
|
#15
|
||||
|
||||
|
no... its to do with the lazy way I do bounces... I just basically undo the last move. what I should do is calculate how much farther than the boundary the ball travelled and subtract that distance from the boundary position but it was two am and it would have added lots of extra code to explain. This is easy and almost as good
![]() -lazypig |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Advanced Drag and Drop | stevenhanton | General Flash | 0 | 03-07-2009 06:00 PM |
| Drag and Drop | ScottyEvil | Flash MX 2004 |
1 | 05-18-2007 05:02 PM |
| Drag & Drop: Deleting when pulled off main area | GrittyKitty | Newbies |
6 | 12-01-2006 10:42 PM |
| Drag & Drop Help! | jmwebcenter | Flash MX 2004 |
1 | 02-08-2004 07:27 PM |
| How to unable Drag and Drop movies. | choi_kathryn | Flash 5 Actionscript |
1 | 11-30-2002 02:14 PM |



...

...OK!
(this is all still Flash 4 compatable by the way)
Twitter
