AddThis Social Bookmark Button
Tutorial part 1 : The basics
The second parameter lock can be set to true or false, if set to true the movie clip will be aligned with the mouse cursor with its registration point. In the previous code change that parameter to false and see what happen.

The last parameters, left, top, right, bottom are used to defined a drag area. This can be useful if you don't want a movie clip to be dragged out of a specific area see the movie below :



In the above movie I have just drawn a 400x300 rectangle (registration point in the center), converted it a s movie clip, named it myRectangle and centered it on the stage. Then I have added the left, top, right and bottom parameters to the code (The only changes to the previous code are colored in white). The coordinates here are defined in reference to the root of the movie.

redCircle.onPress = function(){
startDrag(this,true
,100,75,450,325)
}

redCircle.onRelease = function(){
this.stopDrag();
}

If you play a bit with the drag on the above movie you will notice that if you release the mouse outside of the grey rectangle area and then if you come back inside the rectangle you won't be able to release the drag unless you reclick on it to reset the startDrag action. This happens because we haven't defined an onReleaseOutside event, let's do it now.

redCircle.onPress = function(){
startDrag(this,true,100,75,450,325)
}

redCircle.onRelease = function(){
this.stopDrag();
}


redCircle.onReleaseOutside = function(){
this.stopDrag();
}

You can test the movie below and see that the drag will stop even if you release the mouse outside the grey rectangle :



Continue to next page...
AddThis Social Bookmark Button
If you think this page is providing useful information, don't hesitate to leave a comment.

[ 1 comment ]

flashvalley
 
Copyright ©2006-2008 flashvalley.com - All rights reserved