Through the production of this example, to strengthen the understanding of the previous knowledge, and learn how to work together to achieve better results, with a simple method to create a cool three-dimensional effect, in combination with the creation of a deeper understanding of the application.
This example idea:<1> create instance background.
<2> draw the front and back sides of the card and convert it to a graphic component.
<3> Create a container for the card, convert to the component class "card", put the positive and negative cards in the 1th, 2 frames respectively.
<4> Create a document class that controls the RotationY properties of the Poker object.
Instance steps: (1) Create a blank document, set the stage size to 500*250, set the frame rate to 120, draw a rectangle with the same size as the stage size, fill the radial gradient, and set the first color mark to (r:0,g:246,b:93) alpha:100%, Set the second color label to (r:0,g:131,b:49) alpha:100%, and set the third color label to (r:0,g:62,b:23) alpha:100%, as shown in Figure 15-1 below.
Figure 15-1 Drawing the background
(2) Adjust the high light position and gradient distribution mode using the gradient transform tool, as shown in Figure 15-2 below.
Figure 15-2 Gradient Adjustment
(3) Create two graphic components, named "Back" and "9" respectively. Simply draw the front and back of the poker "9", where the registration point is central and must be the same size, as shown in Figure 15-3 below.
Figure 15-3 Poker opposite
(4) Create a new movie clip named "card" and the name of the symbol class is "card", as shown in Figure 3. The positive and negative faces of the poker "9" created in the previous step are placed at the center of the 1th and 2 frames, as shown in Figure 15-4 below.
Figure 15-4 Creating a "card" object
(5) Create the document class main class, as shown in Figure 3, first create a card container "container" and place it in the center of the stage, as shown in line 20th to 23rd of the constructor, and then create the Poker container object and add it to the container "container", such as 25th, 26 lines of code, and stops playing the Poker container object (that is, the 1th frame), the Start button mode, and the Register listener function, as shown in line 27th to 29th.
Copy Code
The code is as follows:
Package
{
Import flash.display.*;
Import flash.events.*;
Import Caurina.transitions.Tweener;
/**
* ...
* @author lbynet (Tools-> Custom Arguments ...)
*/
public class Main extends Sprite {
private Var Container:sprite;
private Var Pane:movieclip;
private Var Isback:boolean;
private Var Currentplane:movieclip;
private Var Currentrotationy:number;
Public Function Main (): void {
container = new Sprite ();
CONTAINER.X=STAGE.STAGEWIDTH/2;
CONTAINER.Y=STAGE.STAGEHEIGHT/2;
AddChild (container);
pane = new card ();
Container.addchild (pane);
Pane.stop ();
Pane.buttonmode=true;
Pane.addeventlistener (Mouseevent.click, OnClick);
}
6 to call the onclick listener function when the poker container object is clicked, to control when to switch to either the front or the negative for the stage registration event, and to reset the RotationY property of the card by judging the variable isback, as shown in the 36th to 44th line of code, in 38th, 42 lines of code, using Tweener to toggle the RotationY value of the poker between 0 and 180 degrees, as shown in Figure 15-5 below.
Figure 15-5 Document class
Copy Code
The code is as follows:
Private Function OnClick (event:mouseevent): void {
Stage.addeventlistener (Event.enter_frame, Enterframehandler);
Currentplane = MovieClip (event.currenttarget);
if (isback) {
Tweener.addtween (Currentplane, {rotationy:0,time:1});
Tweener.addtween (Currentplane, {z:0,time:1});
} else {
Tweener.addtween (Currentplane, {rotationy:-180,time:1});
Tweener.addtween (Currentplane, {z:-200,time:1});
}
Isback =! Isback;
}
Private Function Enterframehandler (event:event): void {
Currentrotationy = Currentplane.rotationy;
if (currentrotationy >= -90 && currentrotationy <= 10) {
if (isback) {
Currentplane.gotoandstop (2);
} else {
Currentplane.gotoandstop (1);
}
Stage.removeeventlistener (Event.enter_frame, Enterframehandler);
Trace ("Cleared event listener");
}
}
}
(7) When the user clicks the Poker container object, after registering the listener in line 34th code, executes the listener function Enterframehandler and determines which frame the poker container object is to switch to, by always judging the value of the rotationy of the Poker container object. As shown in line 50th to 59th, finally, clear the unwanted listener, as shown in the 57th line of code.
(8) To put the OnClick listener function in the 39th, 432 line code release, publish test, when the user clicks on the Poker container object, the poker switch flips and zooms in (it actually decreases the value of the z axis of the object), as shown in Figure 3 below-When you click again, the poker switch flips and shrinks the original state.
>> from "Flash CS4 animation design and production of 208 cases" (reprint please retain the source)