• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 7. Controlling the Movie Clip > Swapping Overlapping Movie Clips

Swapping Overlapping Movie Clips

When you have multiple draggable movie clips, you'll notice that the objects maintain their stacking order even while being dragged, which can seem a little odd. You would expect that the one you pick would come to the top. You can make it do so by using the swapDepths action to swap the stacking order of movie clips dynamically. swapDepths can switch the stacking order of movie clips either by swapping two named movie clips or by swapping a named movie clip with whatever movie clip is in a designated depth level. The depth level is a number that refers to a movie clip's stacking order. Higher depth-level numbers will overlap lower ones, much like levels of loaded movies. The amazing thing about swapDepths is that it even works across layers, so a movie clip in the bottom layer can swap with a movie clip in the topmost layer.

To swap a movie clip with another movie clip:

1.
Create two draggable movie clips as outlined earlier in this chapter. They should be two different symbols.

2.
Place instances of both movie clips on the Stage in the same layer. In the Instance panel, name both instances.

3.
Go to symbol-editing mode for the first draggable movie clip, and select the movie clip's invisible button.

4.
Open the Actions panel and select the startDrag statement. Choose Actions > evaluate. In the Expression field, enter this.

5.
Choose Objects > Movie Clip > swapDepths.

The swapDepths method appears after this in the Expression field with the word target highlighted (Figure 7.29).

Figure 7.29. Assign the swapDepths action to the on (press) event handler. SwapDepths changes the stacking order of movie clips.


6.
In the Expression field, replace the word target with the target path of the second movie clip (Figure 7.30).

Figure 7.30. The current movie clip and the movie clip puzzle2 swap in the stacking order.


7.
Go to symbol-editing mode for your other draggable movie clip, and add a similar swapDepths statement to its invisible button. In the target field for this swapDepths statement, choose the target path of the first movie clip.

The scripts for both buttons in the two different movie clips should look like the script in Figure 7.31.

Figure 7.31. The swapDepths method is associated with the startDrag action. The button that is assigned the actions on top is in the movie clip called puzzle1. The button that is assigned the actions on bottom is in the movie clip called puzzle2. Both movie clips switch their stacking orders when dragged.


8.
Test your movie.

When you drag the first movie clip, it will swap its stacking order with the second movie clip, and vice versa.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint