|
Defining the drag area for the draggable square instances
We assigned values to the variables top, bottom, left, and right in the draggable square movie clip symbol, using the following script:
onClipEvent (load) {
top=_y-15;
bottom=_y+15;
left=_x-15;
right=_x+15;
}
We opened the draggable square movie clip symbol and selected it on the Stage. Next, we selected set variable from the Actions category in the Toolbox list. For the clip event handler, we left load as the default clip event, indicating that the variables would be set (the values would be assigned) when the movie clip loaded into the Flash Player.
We entered top in the Variable text box. For Value, we selected the Expression option to indicate that the value would be an expression, a formula that calculates whether certain conditions are true. We selected _y from the Properties category in the Toolbox list (for the y coordinate of the movie clip's center point) and then typed -15 to create the expression _y-15 in the Value text boxthat is, the value of the variable top is equal to the y coordinate of the draggable square movie clip minus 15.
We repeated this procedure to set variable names and values for the bottom , left , and right variables, with expressions that set the boundaries of the drag area 15 pixels below, left, or right of the movie clip's position when it loaded.

Setting the expression for the right variable
Let's look again at the script with the startDrag action on the draggable button symbol:
on (press) {
startDrag ("", false, left, top, right, bottom);
dragging=true;
Now that we know the values for the left, top, right, and bottom variables, we can see that the arguments for the startDrag action specify that the button can be dragged 15 pixels in each direction from the button's center point (which is the same as the draggable square movie clip's center point). The bounding box represented by this rectangle equals the perimeter of the mid-sized square movie clip. So, in other words, the draggable button can be dragged anywhere within the perimeter of the mid-sized square movie clip in which it is placed.
Using variables instead of numeric values to specify the bounding box for the drag area allows us to use the same script for all five buttons in the movie, instead of creating five button instances with five different scripts.
|