Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / General Flash Topics / July 2008



Tip: Looking for answers? Try searching our database.

[fla8] snap to object at runtime?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sweetman - 14 Jul 2008 08:19 GMT
Hi all,
is there a way to enable some sort of 'snap to object' to draggable
objects in a movie at runtime?
I'm creating a tiny app that will allow the user to drag object and
align them side-by-side. Aligning them in a perfect way is almost
impossible. If only I could get them to snap to their nodes/corners...

Any idea?

thanks in advance.

tony
Shan-Dysigns - 14 Jul 2008 15:51 GMT
Create a movie clip with a hit area shape, reduce it's opacity to 0. Place that
movie clip on the stage with instance name. When someone is dragging an object,
you can use hitTest to determine if it's in the correct spot (at least close
enough) when the mouse is let go. If so, you can assign the object to a defined
x and y coordinate.
DMennenoh **AdobeCommunityExpert** - 14 Jul 2008 16:59 GMT
Writing a simple snap to grid function is pretty easy, and may work well for
what you need. Essentially, you just test the _xmouse and _ymouse using mod,
if mousePos % snapSetting == 0, then you know you're on a grid point.

This should get you started:

var snapSpace = 10;
var myInterval:Number;

clipA.onPress = function(){
myInterval = setInterval(startDragging, 5, this);
}

clipA.onRelease = clipA.onReleaseOutside = function(){
clearInterval(myInterval);
}

function startDragging(clipRef:MovieClip){

if(_xmouse % snapSpace == 0){
 clipRef._x = _xmouse;
}
if(_ymouse % snapSpace == 0){
 clipRef._y = _ymouse;
}
}

Signature

Dave -
www.offroadfire.com
Head Developer
http://www.blurredistinction.com
Adobe Community Expert
http://www.adobe.com/communities/experts/

Shan-Dysigns - 14 Jul 2008 18:58 GMT
I think the question was to snap to other objects (not just a grid of some
kind). Here is an example I made for you. I think it's simple enough for you to
get the idea and figure out how to implement it into your flash. It's nothing
fancy, just fundamental.

Look at my example http://www.shan-dysigns.com/flash/hitTest.fla
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.