|
|
The Page Turn Effect in Flash MXby Sham Bhangal, author of Flash Hacks09/03/2004 In Hack #25 of Flash Hacks, I talk in general terms about how symmetry can aid the thought and design processes when you are developing scripted effects, because symmetry is a very common feature in both natural and man-made effects. I go on to show how to deconstruct one of the most recent "How is that done?" effects, the page turn, by looking for symmetry in the effect. What I don't cover is how to develop code that can be used to create the page turn effect. This article provides that part of the equation. The development of the page turn hack is a useful exercise to develop, because it contains three of the most common tricks in Flash motion graphics effects--property-based animation, embedded movie clips, and masking. The last two are features that seem to confuse developers coming to Flash from other web programming languages. Having a good understanding of how these two features are used in the page turning exercise is instructive in learning how complex graphical effects are built up in Flash, because you can rarely create such effects using traditional property-based animation alone. The source files developed in this article can be found on the download page for the Flash Hacks book. Although the code presented in this article is for Flash MX 2004, you will also find additional source files that are compatible with Flash MX for this hack (and almost all of the other hacks in the book) on the download page. Symmetry and Page TurningThe symmetry of a turning page is shown below. Assuming that the turning page is folded right over, the shape of the two revealed pages is always symmetrical around the fold.
In any coded version of the page turn effect, creating this line of symmetry is a crucial first step. During the page turn, a number of things happen. The first is that the original page (area a) slowly disappears, and is replaced by the reverse edge of the turning page (area c). As the original page disappears, the page underneath it appears (area b).
The second step in working out how to create the code is in deciding which of the three areas (a, b, or c) that our code has to control. Symmetry tells us that we will have a much easier life if we chose to consider b and c. How do I know that a is irrelevant?
Not only does symmetry help us deduce the way the page turn works, but considering symmetry also helps us to find the easiest solution! We can now split the process of finding a programmed solution to animating the page turn effect into three parts:
We will tackle each in turn below. Creating the Line of SymmetryLooking at the previous diagrams, we see that the line of symmetry in the page turn effect starts at 45 degrees and moves towards the book spine. As it reaches the spine, the line of symmetry is at 90 degrees (straight up), giving us a fully open page on either side of the line of symmetry. The interactive diagram below shows the required motion for the line of symmetry. Click-drag the circle at the bottom of the dotted line to see the line of symmetry move as per the final effect.
When interacting with this diagram, you should see that:
This gives us the following equation for the angle of the line of symmetry, assuming that we have created this line as a movie clip with instance name line:
(Note: the line movie clip points straight up when it is at 90 degrees; hence,
the above equation is really subtracting an angle between 0 and 45 degrees as the
position of the line is moved between The rest of the code in the listing is pretty self-explanatory. The function Within The
|
|
|
|
|
||||||||