LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 




ReplyREPLY THREAD
 
Thread Tools Display Modes
  #1  
Old 03-21-2001, 11:31 AM
barrybell barrybell is offline
Registered User
 
Join Date: Mar 2001
Posts: 22
Rep Power: 0
barrybell is on a distinguished road
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?
Reply With Quote
  #2  
Old 03-22-2001, 01:51 PM
Inf Whale's Avatar
Inf Whale Inf Whale is offline
Registered User
 
Join Date: Sep 2000
Location: Sweden
Posts: 128
Rep Power: 13
Inf Whale is on a distinguished road
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!
Reply With Quote
  #3  
Old 03-22-2001, 02:25 PM
barrybell barrybell is offline
Registered User
 
Join Date: Mar 2001
Posts: 22
Rep Power: 0
barrybell is on a distinguished road
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.

Reply With Quote
  #4  
Old 03-23-2001, 12:15 PM
Inf Whale's Avatar
Inf Whale Inf Whale is offline
Registered User
 
Join Date: Sep 2000
Location: Sweden
Posts: 128
Rep Power: 13
Inf Whale is on a distinguished road
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!
Reply With Quote
  #5  
Old 03-23-2001, 01:57 PM
barrybell barrybell is offline
Registered User
 
Join Date: Mar 2001
Posts: 22
Rep Power: 0
barrybell is on a distinguished road
Actually....i found something very similar yesterday...just trying to figure out how to adapt it to what i want.

Cheers.
Reply With Quote
  #6  
Old 03-30-2001, 06:06 PM
cleverpig's Avatar
cleverpig cleverpig is offline

Piggy Moderator
 
Join Date: Feb 2001
Location: Singapore
Posts: 712
Rep Power: 13
cleverpig is on a distinguished road
Thumbs Up ...a mini tutorial

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;
}
The script in the first frame of the MC does one of two things depending on whether the clip is currently being dragged or not. It either:
  • if its being dragged, keeps track of the difference between the X and Y positions from frame to frame and stores the differences in variables called 'deltaX' and 'deltaY' (if you remember your maths - delta X is the usual way of referring to 'change in X')
  • if it's not being dragged, adds deltaX to the current X position and DeltaY to the current Y position (does a bit of maths to 'bounce' the clip if it hits the edge of the box), and then diminishes the amount of deltaX and deltaY so that next time round, the clip doesn't move quite so much.

...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;
}
OK... bit by bit. damping = 0.95Damping controls the amount that deltaX and deltaY decrease by each frame after you let go of the MC. 0.8 would stop quickly. 0.999 would give you time to go make coffee before it stopped. 0.95 is a nice value to see the effect. If you set the value greater than 1, it will accelerate and eventually go out of control... 1.005 is a good value to see this effect.

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
Reply With Quote
  #7  
Old 03-30-2001, 06:50 PM
Av Av is offline

Super Moderator
 
Join Date: Aug 2000
Location: England
Posts: 960
Rep Power: 13
Av has disabled reputation
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~
__________________
Remember, before you post, SEARCH

old F5 tuts here

av@flashmove.com
Reply With Quote
  #8  
Old 03-30-2001, 06:57 PM
cleverpig's Avatar
cleverpig cleverpig is offline

Piggy Moderator
 
Join Date: Feb 2001
Location: Singapore
Posts: 712
Rep Power: 13
cleverpig is on a distinguished road
sure... but there's no commenting inside there so you probably want to paste the explanation as well...

please give credit tho...
Reply With Quote
  #9  
Old 03-30-2001, 07:43 PM
cleverpig's Avatar
cleverpig cleverpig is offline

Piggy Moderator
 
Join Date: Feb 2001
Location: Singapore
Posts: 712
Rep Power: 13
cleverpig is on a distinguished road
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;
}
Reply With Quote
  #10  
Old 03-30-2001, 07:46 PM
cleverpig's Avatar
cleverpig cleverpig is offline

Piggy Moderator
 
Join Date: Feb 2001
Location: Singapore
Posts: 712
Rep Power: 13
cleverpig is on a distinguished road
...hey, wierd bug in my code... try putting the mc right up against the right hand edge!
Reply With Quote
  #11  
Old 03-31-2001, 12:53 AM
Av Av is offline

Super Moderator
 
Join Date: Aug 2000
Location: England
Posts: 960
Rep Power: 13
Av has disabled reputation
Rolleyes

Umm, the ball sunk

Why ?

~Av~
__________________
Remember, before you post, SEARCH

old F5 tuts here

av@flashmove.com
Reply With Quote
  #12  
Old 03-31-2001, 01:08 AM
cleverpig's Avatar
cleverpig cleverpig is offline

Piggy Moderator
 
Join Date: Feb 2001
Location: Singapore
Posts: 712
Rep Power: 13
cleverpig is on a distinguished road
Big Grin

...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
Reply With Quote
  #13  
Old 03-31-2001, 01:37 AM
cleverpig's Avatar
cleverpig cleverpig is offline

Piggy Moderator
 
Join Date: Feb 2001
Location: Singapore
Posts: 712
Rep Power: 13
cleverpig is on a distinguished road
...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;
    }
-because the code is all contained within the MC, you can duplicate it as many times as you like on the stage... I should have pointed this out before.
__________________
CleverPig : Non plaudite. Modo pecuniam jacite
Reply With Quote
  #14  
Old 03-31-2001, 08:07 AM
FlashMove's Avatar
FlashMove FlashMove is offline

FlashMove Master
 
Join Date: Jan 2000
Location: Singapore
Posts: 4,597
Rep Power: 10
FlashMove is on a distinguished road
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?
__________________
Actionscript tag . Donate Here . Testimonial . Join Flash Chat UserGroup . Twitter . Facebook
Reply With Quote
  #15  
Old 03-31-2001, 08:22 AM
cleverpig's Avatar
cleverpig cleverpig is offline

Piggy Moderator
 
Join Date: Feb 2001
Location: Singapore
Posts: 712
Rep Power: 13
cleverpig is on a distinguished road
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
Reply With Quote
ReplyREPLY THREAD


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

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




All times are GMT. The time now is 12:47 PM.