The Movie Clip Object

The movie clip object is unique among all other objects because it can be created manually or with ActionScript. It also has a timeline that is independent from the main timeline. This means that you can have content on a movie clip's timeline that runs on its own, unconnected from its parent timeline.

The movie clip object also has an extensive list of properties, methods, and events. It can also handle button events, so you can see why it is the most popular object to use in Flash.

In this example, we will create a movie clip manually, and then control it with ActionScript.


Create a new Flash document.


Draw a circle on the stage about 100 pixels in width and height.


Highlight the circle by using both stroke and fill, and choose Modify>Convert to Symbol.


Give it a symbol name of circleMC and make sure the behavior is set for Movie clip.


Back in the main timeline, give the instance of the circle an instance name of circle_mc in the properties inspector.


Create a new layer called actions.


In the first frame of the actions layer, open up the Actions panel, and place this code in it:

 //create the speed variable var speed:Number = 10; //the event to move the circle circle_mc.onEnterFrame=function(){     //get the distance between the mouse and the circle     var xDist = _xmouse-this._x;     var yDist = _ymouse-this._y;     //set the circles position     this._x+=xDist/speed;     this._y+=yDist/speed; } 

The preceding code first creates a variable to control the speed of the circle. Then it simply creates a callback function that continually fires. In this callback, we get the distance between the circle and the mouse on both the horizontal and vertical plane. We then set the circle's position based on that distance.

Now test the movie and move the mouse around on the screen. You will see that the circle_mc movie clip follows the mouse wherever it goes while still on the screen.

You can find more information on the movie clip object in Chapter 13, "The Movie Clip Objects."

Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319 © 2008-2017.
If you may any questions please contact us: