| 1 |
Choose File > Open and choose the version of the MyPuzzle.fla file that you last saved. |
| 2 |
Click the Symbols button in the upper right corner of the Timeline and choose Misc > Piece actions.
|
|
The Piece actions movie clip opens in symbol-editing mode. |
| 3 |
Choose Window > Actions to open the Actions panel. |
| 4 |
In the Actions panel, select the following line of code: |
|
|
| 5 |
Double-click the onClipEvent action in the Action category. Choose the Mouse down event. |
|
The onClipEvent action is a special type of action called an event handler, or just handler. A handler allows you to write code that runs when a certain event occurs. For example, when the mouse button is pressed, the playhead enters a frame, and a movie clip loads. |
|
In this procedure, the code within the curly brackets that follow the onClipEvent handler runs when a user presses the mouse button in the movie. |
| 6 |
Double-click the with action in the Action category in the Toolbox to add it to the script. |
|
The with action allows you to specify a movie clip and write actions as if you were on the Timeline of that movie clip. |
| 7 |
Enter whichOne in the Object box. |
|
The whichOne variable is set within the onClipEvent(load) handler. The value of whichOne is _parent._parent . The property _parent refers to the instance name of the movie clip within which the current clip is nested. The code _parent._parent points to the movie clip two levels above the current clip. The _parent property allows you to reuse this script in each of the 50 puzzle pieces because it acts on movie clips relative to it and doesn't require you to know the instance name of each clip. For this purpose, the _parent property allows you to create relative paths. |
| 8 |
Double-click the if action in the Toolbox list. |
| 9 |
With the insertion point in the Condition box, click Objects in the Toolbox to open the Objects category. Then click MovieClip and double-click hitTest in the Toolbox list. The following code appears in the Condition box: |
|
.hitTest( x, y, shapeFlag )
|
|
The hitTest method determines whether a movie clip has collided with either a specific point or another movie clip. In this example, you will use the current mouse position as the specific point in order to test whether the mouse is over a puzzle piece. |
| 10 |
Remove the dot ( . ) from hitTest . |
|
Often, you would specify an instance name before the dot of the hitTest method. However, because you used the with action to specify a movie clip, you don't need to do this. |
| 11 |
Select the x in the Condition box and enter _root._xmouse. Select the y and enter _root._ymouse. |
|
The hitTest method (just like a function) takes certain arguments. Two of these are x and y , which specify the x and y coordinates of a point. You use the _xmouse and _ymouse properties to determine the location of the mouse in the movie. If the mouse collides with the movie clip, the hitTest method returns the value true and the actions inside the if statement will run. |
| 12 |
Select shapeFlag and substitute it with the value true. The code looks like this: |
|
onClipEvent (mouseDown) {
with (whichOne) {
if (hitTest( _root._xmouse, _root.ymouse, true )) {
}
}
}
|
| 13 |
Place the insertion point after the parentheses that enclose the hitTest arguments and enter && _root.actions.dialog == false. |
|
You need to check that the dialog variable is false because you don't want this function to be called if a dialog box is visible on the Stage. Players shouldn't be able to rotate or drag a piece, or display its piece number if a dialog box is showing. |
| 14 |
Double-click the evaluate action in the Action category in the Toolbox list to add it inside the curly brackets of the if statement. |
| 15 |
In the Expression box, enter _root.actions.RotateDisplayOrDrag(_name). The final code looks like this: |
|
onClipEvent (mouseDown) {
with (whichOne) {
if (hittest(_root._xmouse, _root._ymouse, true) &&
_root.actions.dialog == false) {
_root.actions.RotateDisplayOrDrag(_name);
}
}
}
|
| 16 |
Choose Edit > Movie to return to the main Timeline. |
| 17 |
Choose File > Save As and enter a new filename. For example, if your file is called Jean_Puzzle7.fla, you could name it Jean_Puzzle8.fla. This allows you to revert to earlier versions of the file. |
 |
|