-
In Window Snapping
Hey guys.
I'm working on a real quick project that is similar to making a blue print. It will have a grid and you just drag items onto it. As a little bonus I would like each piece to snap to the grid. I actually know how to do that but only to an extent. Here I'll show you what I'm working with:
Snapping.png
So the blue box is stationary and does not move and the other two boxes can be clicked and dragged. The pink box alone will snap (after letting go) because it is smaller than the blue. However, for my purposes, I want the items to be bigger than each piece of the grid, thus the green box being bigger. Ideally, people will drag that green/pink box and after letting go it will center itself in the blue box. The main problem is that the movie clip is now larger than the item it is snapping to. Any idea how to fix this?
Green Box instance name = Snap1
Pink Box instance name(inside Snap1) = Snap2
Blue Box instance name = Snap3
=====Code======
Snap1.onPress = function()
{
Snap1.startDrag();
};
Snap1.onRelease = function()
{
if(this.Snap1.Snap3._droptarget=="/Sprite4")
{
// align Sprite3
this.Snap1.Snap3._x = Snap2._x + (Snap2._width-this.Snap1.Snap3._width)/2;
this.Snap1.Snap3._y = Snap2._y + (Snap2._height-this.Snap1.Snap3._height)/2;
};
Snap1.stopDrag();
};
Thanks so much!
-
I messed up the code above when I changed the instance names, here is what it should be:
Snap1.onPress = function()
{
Snap1.startDrag();
};
Snap1.onRelease = function()
{
if(this.Snap1.Snap3._droptarget=="/Snap2")
{
this.Snap1.Snap3._x = Snap2._x + (Snap2._width-this.Snap1.Snap3._width)/2;
this.Snap1.Snap3._y = Snap2._y + (Snap2._height-this.Snap1.Snap3._height)/2;
};
Snap1.stopDrag();
};
-
Designer, Programmer, Musician
Here is a tutorial i made for you last week. I couldn't connect to internet until today ...so sorry for the delay :P
http://www.mediafire.com/?k73ykh5idvdaz
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
.
Him
If your movieclips have central registration points then you can use
PHP Code:
Snap1.onPress = function()
{
startDrag(this);
};
Snap1.onRelease = function()
{
if (eval(this._droptarget) == Snap3)
{
this._x = Snap3._x;
this._y = Snap3._y;
this._alpha = 50;
}
else
{
this._alpha = 100;
}
stopDrag();
};
alpha added for effect, it can be removed
-
Designer, Programmer, Musician
New stuff for me... i will read about the eval property...
Last edited by angelhdz; 12-10-2013 at 01:40 PM.
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|