CO.CC:Free Domain
Google
Custom Search
Monday, July 7, 2008

The Movie Clip Symbol on flash

We have saved the best for last in this chapter because the movie clip has it all. Movie clips have an independent timeline in that their timeline is not dependent on the main timeline; therefore, their play head can move in sync or out of sync with the main play head. Also, movie clips can have ActionScript within their own timeline and/or have ActionScript in their object actions. The main timeline itself is a movie clip, although you won't find it in the Library panel with the others. Movie clips are so powerful. Making a Movie Clip symbol is the same as making the other symbols, but you choose a different behavior.

1.
Create a new Flash document and save it as myFirstMovieClip.fla.
2.
Draw a circle in the center of the stage about 75x75 and give it a red fill color (0xff0000).
3.
Select the circle, both stroke and fill, and choose Modify, Convert to Symbol (F8).
4.
In the Convert to Symbol dialog box, give it a symbol name of circleMC, choose Movie Clip for the behavior, and click OK.

If you tested the movie right now, the square would be there. But if that was all you were going to do, you could have used a graphic. Instead, you will go back into the movie clip and add some ActionScript to make the circle interactive.
5.
Back on the main timeline, select the circle movie and open the Actions panel by choosing Window, Actions (F9).
6.
In the object actions of the circle, place the following code:
onClipEvent(mouseDown){
//if the user clicks the circle
if(hitTest(_root._xmouse,_root._ymouse)){
//drag the circle
this.startDrag(false);
}
}
//when the user lets go
onClipEvent(mouseUp){
//stop dragging the circle
stopDrag();
}

Do not worry if the code is new to you, it will be covered in later chapters, but the code is necessary so that you can see the power of movie clips.
Test the movie at this point, and you will see that if you click the circle and move the mouse, the circle will drag. Let go and the movie will stop dragging.

0 komentar: