throwing & dragging objects...
Hi,
I am trying to complete a drag and drop feature with multiple objects. I can get a single object to work perfectly... it drags and opens to another screen when double clicked. Trouble is when I try to add another object only one will work.... Please help, this is causing me major headaches!!!
Here's the code I've got....
dragging = false;
friction = 0.98;
bounce = -0.7;
gravity = 0.5;
top = 0;
left = 0;
bottom = Stage.height;
right = Stage.width;
pic._x = Stage.width / 2;
pic._y = Stage.height / 2;
vx = Math.random() * 10 - 5;
vy = Math.random() * 10 - 5;
pic.onPress = function()
{
oldX = pic._x;
oldY = pic._y;
dragging = true;
pic.startDrag();
};
pic.onRelease = function()
{
dragging = false;
pic.stopDrag();
if (C1) {
if(getTimer() < t1+500){
C1 = 0;
getURL ("http://www.eyekiller.com/flash.htm")
}
} else {
C1 = 1;
t1 = getTimer();
}
};
pic.onReleaseOutside = function()
{
dragging = false;
pic.stopDrag();
};
this.onEnterFrame=function()
{
if(C1 && getTimer() >= t1+500){
C1 = 0;
}
if (!dragging)
{
vx *= friction;
vy *= friction;
pic._x += vx;
pic._y += vy;
if (pic._x + pic._width / 2 > right)
{
pic._x = right - pic._width / 2;
vx *= bounce;
}
else if (pic._x - pic._width / 2 < left)
{
pic._x = left + picl._width / 2;
vx *= bounce;
}
if (pic._y + pic._height / 2 > bottom)
{
pic._y = bottom - pic._height / 2;
vy *= bounce;
}
else if (pic._y - pic._height / 2 < top)
{
pic._y = top + pic._height / 2;
vy *= bounce;
}
}
else
{
vx = pic._x - oldX;
vy = pic._y - oldY;
oldX = pic._x;
oldY = pic._y;
}
};
dragging = false;
friction = 0.98;
bounce = -0.7;
gravity = 0.5;
top = 0;
left = 0;
bottom = Stage.height;
right = Stage.width;
ball._x = Stage.width / 2;
ball._y = Stage.height / 2;
vx = Math.random() * 10 - 5;
vy = Math.random() * 10 - 5;
ball.onPress = function()
{
oldX = ball._x;
oldY = ball._y;
dragging = true;
ball.startDrag();
};
ball.onRelease = function()
{
dragging = false;
ball.stopDrag();
if (C1) {
if(getTimer() < t1+500){
C1 = 0;
getURL ("http://www.eyekiller.com/flash.htm")
}
} else {
C1 = 1;
t1 = getTimer();
}
};
ball.onReleaseOutside = function()
{
dragging = false;
ball.stopDrag();
};
this.onEnterFrame=function()
{
if(C1 && getTimer() >= t1+500){
C1 = 0;
}
if (!dragging)
{
vx *= friction;
vy *= friction;
ball._x += vx;
ball._y += vy;
if (ball._x + ball._width / 2 > right)
{
ball._x = right - ball._width / 2;
vx *= bounce;
}
else if (ball._x - ball._width / 2 < left)
{
ball._x = left + ball._width / 2;
vx *= bounce;
}
if (ball._y + ball._height / 2 > bottom)
{
ball._y = bottom - ball._height / 2;
vy *= bounce;
}
else if (ball._y - ball._height / 2 < top)
{
ball._y = top + ball._height / 2;
vy *= bounce;
}
}
else
{
vx = ball._x - oldX;
vy = ball._y - oldY;
oldX = ball._x;
oldY = ball._y;
}
}; :yikes: