Working with Movie Clips and Buttons > Using actions and methods to control movie clips |  |

Using actions and methods to control movie clips

You can use ActionScript actions or the methods of the MovieClip object to perform tasks on movie clips. Some MovieClip methods perform the same tasks as the actions of the same name; other MovieClip object methods, such as `hitTest` and `swapDepths`, don't have corresponding actions.

When an action and a method offer similar behaviors, you can choose to control movie clips by using either one. The choice depends on your preference and familiarity with writing scripts in ActionScript. Whether you use an action or a method, the target Timeline must be loaded in the Flash Player when the action or method is called.

The following actions target movie clips: `loadMovie`, `unloadMovie`, `loadVariables`, `setProperty`, `startDrag`, `duplicateMovieClip`, and `removeMovieClip`. To use these actions, you must enter a target path for the action's `target` parameter to indicate the target of the action.

The following MovieClip methods can control movie clips or loaded levels and do not have equivalent actions: `attachMovie`, `createEmptyMovieClip`, `createTextField`, `getBounds`, `getBytesLoaded`, `getBytesTotal`, `getDepth`, `globalToLocal`, `localToGlobal`, `hitTest`, `setMask`, `swapDepths`.``

To use a method, invoke it by using the target path of the instance name, a dot, and then the method name and parameters, as in the following statements:

    myMovieClip.play();
    parentClip.childClip.gotoAndPlay(3);

In the first statement, the `play` method moves the playhead in the `myMovieClip` instance. In the second statement, the `gotoAndPlay` method sends the playhead in `childClip` (which is a child of the instance `parentClip`) to frame 3 and continues to move the playhead.

Actions that control a Timeline have a `target` parameter that allows you to specify the target path to the instance that you want to control. For example, in the following script the `startDrag` action targets the `customCursor` instance and makes it draggable:

    on(press){
    	startDrag("customCursor");
    }

The following example illustrates the difference between using a method and using an action. Both statements duplicate the instance `myMovieClip`, name the new clip `newClip`, and place it at a depth of 5.

    myMovieClip.duplicateMovieClip("newClip", 5);
    duplicateMovieClip("myMovieClip", "newClip", 5);

For more information about these actions and methods, see the online ActionScript Dictionary in the Help menu.