Tutorial details:
Written by: Thomas Barslund
Difficulty Level: advanced
Requirements: Flash 4,5
Download FLA In order to understand the following properly, you should be well acquainted with ActionScript, since the file requires some advanced scripting knowledge.


Thanks to Joshua Davis for allowing us to duplicate his original effect from www.praystation.com in this tutorial.

The idea
The idea is to have a box, which contains a number of objects. When the cursor is located inside the box, then we want to apply a scale and alpha value to each object dependent on the distance between each object and the cursor. On the other hand, when the mouse is located outside the box, we want each object to return to its original state.

The structure
On the main stage, you’ll find a movie clip called “01 – boundingbox” and some actions in frame 1, which set the player so that the movie is always drawn at 100% and the image is never scaled, return the player to normal menu view and stop the file (this is necessary because of the comments):
FS Command ("fullscreen", "false")
 FS Command ("allowscale", "false")
 Stop

Inside “01 – boundingbox” you’ll find three layers, which contain an empty movie clip, the box and our objects, which have been stored inside a movie clip named “column1”. There is only one action in frame 1, which simply makes the centre of the movie clip (“dragscale”) appear directly under the mouse pointer. This is necessary, since we want to determine the distance between the cursor and our objects:
Start Drag ("dragscale", lockcenter)

The crucial actions are located in frame 2 inside “column1”; the action in frame 3 simply insures that the actions in frame 2 are carried out continuously:
Go to and Play (2)

You’ll notice that there are 20 layers, where the first contains our actions and the rest our objects. Furthermore, object 1 and 19 (the first and last) are empty, which is because we do not want our objects to be scaled beyond the box. These objects have been called “text” followed the object’s number (e.g. the first is called “text1” and the last “text19”).

Initialising our environment
In frame 2, you’ll find the following actions:
Set Variable: "colnum" = 1
 Set Variable: "startnum" = 1
 Set Variable: "endnum" = 19
 Set Variable: "numberofItems" = 19
 Set Variable: "mouseposX" = Int ( GetProperty ( "../dragscale", _x ) )
 Set Variable: "mouseposY" = Int ( GetProperty ( "../dragscale", _y ) )
 Set Variable: "i" = startnum
 Set Variable: "m" = startnum+1
 Set Variable: "filledSpace" = 0
 Set Variable: "gapspace" = 0
 If (myInit = FALSE)
   //Comment: on first run make an array of all the text Y Pos.
   Loop While (i <= endnum)
     Set Variable: "textY" & i = GetProperty ("text" & i, _y )
     Set Variable: "i" = i + 1
   End Loop
   Set Variable: "i" = startnum
   Set Variable: "myInit" = TRUE
 End If
 Set Variable: "boundleft" = GetProperty ("../boundbox" & colnum, _x)
 Set Variable: "boundright" = boundleft + GetProperty ("../boundbox" & colnum, _width)
 Set Variable: "boundtop" = GetProperty ("../boundbox" & colnum, _y)
 Set Variable: "boundbottom" = boundtop + GetProperty ("../boundbox" & colnum,_height)

The first variable is simply the number of the box. In this case, we’re located inside box no. 1 (“column1”). The next three variables are the starting and ending number and the number of objects ("startnum", "endnum" and "numberofItems"). We then determine the coordinates of the mouse by storing them in the next two variables "mouseposX" and "mouseposY". Furthermore, we need counters for the loops, which are called "i" and "m". Finally, we reset two variables, "filledSpace" and "gapSpace", which will be discussed later in this document.

Since we want our objects to have an original position, we need to make an array, which holds these values. When we have stored an original vertical position for each object, we reset "i" for further usage and ensure that these actions will only be performed the first time, by setting "myInit" to true (the actions are only carried out, if "myInit" is false). As mentioned, we only want to apply a scale and alpha value to each object, if the mouse is located inside the box and thus we need to know the borders, which the next four variables take care of ("boundleft", "boundright", "boundtop" and "boundbottom").

After we have initialised our environment, we have two cases, where mouse is located either inside the box or outside the box.