Effect Demo:
1. Create a new Flash document, click the Size button in the Properties panel, and open the document Properties panel to set the scene size to 350px x 300px and the frame frequency to 20fps.
2. Press the shortcut key Ctrl+f8 to create a new movie clip symbol named "Picture." Press the shortcut key Ctrl+r Open the import panel to import a landscape picture that can cover the scene.
3. Press the shortcut key ctrl+l to open the library panel and drag the picture component to scene 1. Click the "Picture" component in the scene, press the shortcut key ctrl+k to open the "Align" Panel, tap the "relative to Stage" button, and then click the "left" and "Up" button. This makes it easy for the "picture" component to cover the entire scene.
4. Create a "bird" movie clip symbol. The layer of the component sets the "left wing" layer and the "right wing" layer to use the "shape gradient" movement to allow two line segments to simulate the movement of bird wing agitation. Open the Onion skins command and you can see it clearly. In each frame, the line segment is only different in angle to produce the effect of motion. To set the angle of the line segment, you can press the shortcut key ctrl+t to open the variants panel for secondary settings.
5. Press the shortcut key ctrl+l to open the library panel. Right-click the bird component in the library and click the link command to open the Link Properties panel (click to export the action script and export in the first frame). After you define a movie clip symbol by using the link Properties panel, you can invoke the symbol directly from your code without dragging the component to the scene.
6. Back to Scene 1, click the 1th frame of layer 1, press F9 to open the Actions panel and enter the following code:
Bird Animation
damp =. 95;
Numbirds = 30;
For (i=0 i<numbirds; i++) {
Bird = Attachmovie ("Bird", "Bird" +i, i);
bird._x = Math.random () *350+20;
Bird._y = Math.random () *300+20;
BIRD.VX = Math.random () *10-5;
Bird.vy = Math.random () *10-5;
BIRD.K = Math.random () *.0001+.0003;
Bird.gotoandplay (Math.Round (Math.random () *20));
}
Onenterframe = function () {
var totx = 0;
var toty = 0;
For (i=0 i<numbirds; i++) {
Bird = _root["Bird" +i];
Totx + = bird._x;
Toty + = bird._y;
}
AVGX = Totx/numbirds;
Avgy = Toty/numbirds;
For (i=0 i<numbirds; i++) {
Bird = _root["Bird" +i];
BIRD.VX + = (avgx-bird._x) *bird.k;
Bird.vy + = (avgy-bird._y) *bird.k;
BIRD.VX + + math.random ()-.5;
Bird.vy + + math.random ()-.5;
BIRD.VX *= Damp;
Bird.vy *= Damp;
Targangle = Math.atan2 (Bird.vy, BIRD.VX) *180/math.pi;
diff = targangle-bird._rotation;
if (diff<-180) {
diff + + 360;
}
if (diff>180) {
diff-= 360;
}
Bird._rotation + = diff*.2;
Bird._x + = BIRD.VX;
Bird._y + = Bird.vy;
}
}
7. To make the animation more interesting, we add the following code in the above code:
Mouse action
function Drawtopoint () {
for (i=0;i<numbirds;i++) {
bird=_root["Bird" +i];
bird.vx+= (_xmouse-bird._x) *bird.k*100;
bird.vy+= (_ymouse-bird._y) *bird.k*100;
}
}
OnMouseDown = Drawtopoint;