all groups > flash actionscript > february 2005 >
You're in the

flash actionscript

group:

Drag and drop with limits


Re: Drag and drop with limits Byron Canfield
2/18/2005 4:27:39 PM
flash actionscript:
If I had to guess, I would say that by putting that script on frame 1,
you're not allowing enough time for the stage height and width to be
established. Try moving everything later by one frame.

--
--------
Reality will not be altered to comply with preconceived notions.

Byron "Barn" Canfield
Flash example files: http://www.canfieldstudios.com

Drag and drop with limits Jak-S
2/18/2005 11:50:48 PM
Hi

Im trying to do a drang and drop with limits so it cant be dragged off the
stage, can someone tell me why this dosent work, it just locks the image to the
top left corner of the stage and wont move it.

It is supposed to be dragable all over the stage but you shouldnt be able to
drag it away from the edges, i.e. the left hand edge of the image shouldnt come
any furthur ONTO the stage than the very left hand side of the stage.

THIS SCRIPT IS ON FRAME 1:

stageWidth = Stage.width;
stageHeight = Stage.height;
imageWidth = productImage._width;
imageHeight = productImage._height;
limitLeft = stageWidth-imageWidth;
limitTop = stageHeight-imageHeight;
limitRight = imageWidth;
limitBottom = imageHeight;

THIS SCRIPT IS ATTACHED TO THE productImage SYMBOL:

on (press) {
startDrag(this, true, limitLeft, limitTop, limitRight, limitBottom);
}
on (release) {
stopDrag();
}
Re: Drag and drop with limits kglad
2/19/2005 12:06:51 AM
those limits are illogical unless there's some special relationship between
that stage dimensions and productImage's dimensions.

i'm not sure exactly what you want. but if you wanted to keep the left edge
of your movieclip on the left edge of the stage you would use:

limitLeft=0;
limitRight=0;

if you wanted to allow your movieclip to be dragged partially off-stage to the
left (but not completely) and not allowed to have its left edge move beyond the
left edge of the stage you would use:

leftLimit= -productImage._width;
rightLimit=0;

similarly for right, top and bottom.
Re: Drag and drop with limits Jak-S
2/19/2005 12:24:17 AM
sirry i forgot to say, the image is bigger than the stage.

Re: Drag and drop with limits Jak-S
2/19/2005 12:31:28 AM
im pretty sure that the limits are right, because if i put the numbers into the
startDrag function manually it works.

Its just the variables seem to return "undefined" when i access them from the
image script, even tho they have been defined in the first frame.

thanks for your help so far.
Re: Drag and drop with limits kglad
2/19/2005 12:31:39 AM
ohhh, in that case:

limitLeft=Stage.width-productImage._width;
limitRight=0;
limitTop=Stage.height-productImage._height;
Re: Drag and drop with limits kglad
2/19/2005 12:32:42 AM
Re: Drag and drop with limits Jak-S
2/19/2005 12:36:11 AM
Re: Drag and drop with limits NSurveyor
2/19/2005 12:44:34 AM
You are not scoping your variables correctly:

on (press) {
startDrag(this, true, _parent.limitLeft, _parent.limitTop, _parent.limitRight, _parent.limitBottom);
}
on (release) {
stopDrag();
Re: Drag and drop with limits kglad
2/19/2005 12:47:08 AM
oops, we missed that error. from your movieclip you have to reference the path
of those limits. for example:

on (press) {
startDrag(this, true, _root.limitLeft, _root.limitTop, _root.limitRight,
_root.limitBottom);
}
on (release) {
stopDrag();
}
Re: Drag and drop with limits Jak-S
2/19/2005 1:10:55 AM
ok, thats great, its all working perfectly now, thanks guys.

now how do i get it to run the "stopDrag" function when the cursor leaves the
stage?

as you may have guessed i am not all that experienced with action script.

thanks again for all your help so far.
Re: Drag and drop with limits kglad
2/19/2005 1:23:12 AM
Re: Drag and drop with limits Jak-S
2/19/2005 1:31:18 AM
ok, i will look into the mose leaving stage thing.

i have however run into another problem. i am loading the image dynamically
from a web server. i have got it into the stage with no problems, and it
displays just fine with this script:

stageWidth = Stage.width;
stageHeight = Stage.height;

loadMovie("http://localhost/Work/Northern%20Runner/northernrunner%202005/images/
store/products/standard/images/1000.jpg", "productImage");
imageWidth = productImage._width;
imageHeight = productImage._height;
productImage._x = 0;
productImage._y = 0;

however when i add the line:

productImage._width = 400;

which i thought should set the width to 400 pixels (the stage size), it
actually stretches the image way over to the right.

I dont quite understand why. I know i need to use the stagewidth variable
anyway later on, but surley this should work without any problems.


Re: Drag and drop with limits Jak-S
2/19/2005 2:00:53 AM
Re: Drag and drop with limits NSurveyor
2/19/2005 2:05:19 AM
AddThis Social Bookmark Button