Drag blue rectangle over the yellow. If you drop the blue one on the yellow, the script will align blue rectangle inside the yellow.
Follow the steps below:
- Launch Flash Designer and choose “blank”.
- Set the frame delay to “Stop” (“Frame” > “Frame Delay”).
- Size the frame at about 300×300. (“Frame” > “Frame Size”)
- Create 1 small and 1 larger shapes with the rectangle tool and give them different fill colors.
- Select smaller shape and click Edit > Convert to Sprite.
- Right-click it and click “Placement Properties”.
- Check the “Action-Script Target” checkbox and click OK.
- Click the other shape and repeat the process.
Smaller shape (blue) should appear as “Sprite3″ and larger (yellow) as “Sprite4″. If necessary rename the sprite: select it and choose “Item” > “Placement Properties”
Choose “Frame” > “ActionScript” and paste the code:
Sprite3.onPress = function()
{
Sprite3.startDrag();
};
Sprite3.onRelease = function()
{
if(Sprite3._droptarget==”/Sprite4″)
{
// align Sprite3
Sprite3._x = Sprite4._x + (Sprite4._width-Sprite3._width)/2;
Sprite3._y = Sprite4._y + (Sprite4._height-Sprite3._height)/2;
};
Sprite3.stopDrag();
};
Press F9 to preview the movie.
_droptarget always returns the path with a leading slash /.
Download source project here




May 4, 2010 at 4:49 am
thanks……
really helpful……for me