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
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(); }
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.
sirry i forgot to say, the image is bigger than the stage.
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.
ohhh, in that case: limitLeft=Stage.width-productImage._width; limitRight=0; limitTop=Stage.height-productImage._height;
You are not scoping your variables correctly: on (press) { startDrag(this, true, _parent.limitLeft, _parent.limitTop, _parent.limitRight, _parent.limitBottom); } on (release) { stopDrag();
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(); }
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.
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.
Don't see what you're looking for? Try a search.
|