View Full Version : mc fall on mouse.up?
tenspeedtodd
September 7th, 2009, 08:15 AM
I'm trying to make the bottle of tequila fall back down to the black line (increasing in speed as it falls) when the mouse button is released, but I'm very stuck & new to AS3. Here is my code so far:
-----------------------------------------------------------------------
function dragBottle(e:MouseEvent):void {
e.target.startDrag();
Mouse.hide();
}
function releaseBottle(e:MouseEvent):void {
Mouse.show();
e.target.stopDrag();
}
tequila_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragBottle);
tequila_mc.addEventListener(MouseEvent.MOUSE_UP,re leaseBottle);
-----------------------------------------------------------------------
and here is the swf file
http://opax.swin.edu.au/~6950841/tequila.swf
Cheers.
anand.as2
September 7th, 2009, 08:32 AM
Hi tenspeedtodd,
I think this may help u
onClipEvent (load) {
startspeed = 20;
gravity = 12.8;
jumping = 0;
}
onClipEvent (enterFrame) {
if (Key.isDown(17) and jumping == 0) {
jumping = 1;
starttime = getTimer()/1000;
startposition = _y;
}
if (jumping == 1) {
time = getTimer()/1000-starttime;
_y = _y-(startspeed-gravity*time);
if (_y>startposition) {
_y = startposition;
jumping = 0;
}
}
}
JoeDurb
September 7th, 2009, 04:06 PM
Previous example code was as2, and a little messy,
This should be almost exactly what you need,
It's untested, so I'm sure something minor is amiss.
my added code is in Green. Good Luck.
function dragBottle(e:MouseEvent):void {
e.target.startDrag();
e.target.DRAGGING=true;
Mouse.hide();
}
function releaseBottle(e:MouseEvent):void {
Mouse.show();
e.target.DRAGGING=false;
e.target.YV=1; //initial drop velocity
e.target.stopDrag();
}
function dropBottle(e:Event) {
if (e.target.DRAGGING) return; //skip out if middle of dragging
if (e.target.y>500) return; //skip out if bottle has fallen to max depth
e.target.y-=e.target.YV;
e.target.YV+=1; //Gravity
}
tequila_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragBottle);
tequila_mc.addEventListener(MouseEvent.MOUSE_UP,re leaseBottle);
tequila_mc.addEventListener(Event.ENTER_FRAME,drop Bottle);
tenspeedtodd
September 16th, 2009, 08:50 AM
Thanks JoeDurb, that was good code.
However there are still a couple of things that I can't get working.
When you run it the bottle is sitting up the top of the screen, but I want it to site on the line at x=445.5 and y=225.1, and when it falls i want it to not go past that put, so as if the line is a bar bench.
Any help with that? Thanks man.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.