Hi! I am new to actionscripting and I figured that the best way to learn was to do something that interest me.
Currently I am trying to do an interactive clip where I need to find the script for “Snap to Place”. I was told that Director had this built in “Snap to Grid” but I think Flash can achieve this too just that the tutorial haven’t been posted.
Thanks for your prompt response but I am afraid its not what I was looking for. My “Snap to Grid” was referring to the interactivity when the flash clip is being played. It is something to do with the actionscript.
It does not start to move the clip until it is clicked on, and released when the mouse is released
It cannot move the clip out of a certain area. I tried using
on (press) {
startDrag (this, false, 120, 60, 312, 304);
}
but I can’t figure out how to use that in conjunction with this script’s ability to set spans.
Thanks for finding that. Now all I need to know is how to set spans; I have an image of a grid that I drew set behind the clip i’m moving. The grid squares are around 13x13 pixels, so I need the ability so that the blocks will only move around 13 pixels at a time each time they are dragged. Do these variables already exist in this script?
(This is what mx’s debugger returned):
Scene=Scene 1 copy, Layer=Rectangle, Frame=1: Line 1: Statement must appear within on/onClipEvent handler
my_mc.onPress = function(){
Scene=Scene 1 copy, Layer=Rectangle, Frame=1: Line 7: Statement must appear within on/onClipEvent handler
my_mc.onRelease = my_mc.onReleaseOutside = function(){
Yup, it doesn’t return any errors if I put it in a frame, but the problem there is that the snippet doesn’t actually do anything that the
on(press){
this.beginDrag(false, 120, 60, 312, 304);
}
on(release, releaseOutside){
this.endDrag();
}
does. Also, I still cannot solve this “span” problem. Maybe some math genius could help me edit the code on http://proto.layer51.com/d.aspx?f=845
to include a variable that affects spans the same way that the snippet on http://proto.layer51.com/d.aspx?f=498
uses xspan and yspan?
Remove the actions on the clip, the actions Sen gave are only meant for the frame and no actions on the clip. The only thing you have to add outside of Sens code is the function scripts from those links.
I know, except for the example that comes at the end of the code on http://proto.layer51.com/d.aspx?f=845. I still don’t understand how to do what you are telling me to do; i’ve spent several hours staring at both sets of code, and cannot figure out how to combine the things I need.
Except it doesn’t combine what it is I want to combine; it doesn’t force the movieclip that I have to jump 13 pixels when the mouse is moved. Instead, the object tracks with the mouse perfectly.
I finally managed to figure out the “snaptogrid” portion of the code. The reason I was having a continued problem was because I had tried affecting changes in the snaptogrid function before, but it had not seemed to make any adjustments at all to the spanning. Using this file, however, I was able to piece things together. To those who don’t know yet, you can only make adjustments top the top/bottom/left/right restraints in numbers divisible by the length/width of your grid boxes. I don’t think i’ll mention how long it took me to figure that one out. Also, if you’re using an object that is half as wide as it is long, it seems to me to be impossible to get the object to equally bound around your whole swf window: a problem more easily avoided than solved, since the point at which the mouse “grabs” the clip is in its center. My grid squares were 18x18 pixels, and I had a square that was 54x108 pixels. After a lot of tweaking (I probably could’ve figured out what to set the left/rights to using math by subtracting 1/2 the width of the clip from the document size, but I thought of this after the fact…save yourselves some time) I managed to get it to stop perfectly once you dragged to the left and right corners of the window, but on the top and bottom it would go either 9 pixels too far, or 9 pixels short of the window’s border. Since you can only affect adjustments to the restraints in sizes of 18 pixels, it would be impossible to fix the problem by fiddling with the numbers. By changing the document’s size, I was able to get the object to bound perfectly around the bottom of the window, but by so doing made it impossible to fix the top without breaking the bottom.