Introduction to ActionScript Tutorial > Use a built-in object |
![]() ![]() ![]() |
Use a built-in object
ActionScript has variables that let you store information; it has functions that let you create special commands and reuse code; it has actions that let you control the flow of a movie; and it has movie clips with properties that you can change.
ActionScript also has another type of element called a built-in object. Objects provide a way of grouping information so that you can use it in a script. Objects can have properties, methods (which are like functions), and constants (for example, the numeric value of Pi).
In the RotateDisplayOrDrag
function that you created in Create commands and reuse code, you used the Key object to determine the last key a user pressed on the keyboard. The Key object is built into ActionScript to allow you to access information about the keyboard.
Another ActionScript object is the MovieClip object. The MovieClip object is a collection of methods that you can use to manipulate movie clips, which are the most fundamental and powerful elements of Flash. To learn more about the special characteristics of the MovieClip object and using movie clips, see Working with Movie Clips and Buttons.
You will now use the onPress
method of the MovieClip object to check whether the mouse pointer is touching a puzzle piece.
1 |
If necessary, choose File > Open and choose the version of the mypuzzle.fla file that you last saved. |
Note: You can also browse to your Flash MX application folder and open Tutorials/ActionScript/Finished/puzzle7.fla. If you do use the puzzle7.fla file, save the file with a new name in your My_Puzzle folder to maintain an unadulterated version of the original file. |
|
2 |
Piece actions is a movie clip nested within each instance of a puzzle piece. To select the Piece actions movie clip from the Library panel hierarchy, click the Edit Symbols button in the lower right corner of the Timeline and choose Misc > Piece actions. |
The Piece actions movie clip opens in symbol-editing mode. |
|
3 |
In the Piece actions Timeline, select Frame 1 of the Actions layer. |
4 |
If the Actions panel is not already open, choose Window > Actions. In the Script pane, select line 3 with the following line of code: |
// ENTER code here |
|
5 |
In the Objects > Movie > MovieClip > Events category of the Actions toolbox, double-click the |
The |
|
In this procedure, the code within the curly brackets that follow |
|
6 |
Type _parent in the Object text box. |
Because Piece actions is nested within the movie clip, |
|
7 |
In the Actions > Conditions/Loops category of the Actions toolbox, double-click the |
8 |
Type !_root.dialog in the Condition text box. The code appears as follows: |
_parent.onPress = function(){ if (!_root.dialog) { { }; |
|
The code that you added in this step tests whether the value of the variable named |
|
9 |
In the Actions toolbox, double-click the |
10 |
Type _root.RotateDisplayOrDrag(_parent._name) in the Expression box. |
|
|
The final code looks like this: |
|
_parent.onPress = function(){ if (!_root.dialog) { _root.RotateDisplayOrDrag(_parent._name); } }; |
|
11 |
Do one of the following to return to the main Timeline: |
![]() |
Choose Edit > Edit Document. |
![]() |
Click the Back button. |
![]() |
Click Scene 1. |
12 |
Choose File > Save As and enter a new filename. Use a consecutive naming scheme so you can revert to earlier versions of the file, if necessary. |
![]() ![]() ![]() |