Effect Fallen Leaves

Bước 1:

_ Tạo file FLA tên “FallenLeaves.fla”.

_ Tạo 5 movieClip trong library đặt tên linkage lần lượt : mc_clip_0,mc_clip_1,mc_clip_2,mc_clip_3,mc_clip_4.

_ Tạo 1 movieClip background trong library đặt tên linkage là : bg_mc

Bước 2: Tạo class “FallenLeaves.as” trong thư mục “com”

package com {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.Event;
import flash.events.TimerEvent;

/**
* @author yoko
*/
public class FallenLeaves extends MovieClip {
// khởi tạo mảng chứa các movieClip lấy từ library
private var clips_array : Array;

private const SPRING : Number = .1;

private var timer : Timer;

public function FallenLeaves() : void {
init();
initTimer();
}

private function init() : void {
stage.frameRate = 31;
this.x = 0;
this.y = 0;
this.width = stage.stageWidth;
this.height = stage.stageHeight;
// attach các movieClip từ library
clips_array = new Array(new mc_clip_0(),new mc_clip_1(),new mc_clip_2(),new mc_clip_3(),new mc_clip_4());
}

private function initTimer() : void {
timer = new Timer(250, 0);
timer.addEventListener(TimerEvent.TIMER, go);
timer.start();
}

private function go(evt : TimerEvent) : void {
var n : Number = Math.floor(Math.random() * clips_array.length);
var clip : MovieClip = clips_array[n] as MovieClip;

clip.x = Math.random() * stage.stageWidth;
clip.y = -clip.height;
clip.center = clip.x;
clip.vel_x = 2 + Math.random() * 10;
clip.vel_y = clip.vel_x;
clip.angle = 0;
addChild(clip);

clip.addEventListener(Event.ENTER_FRAME, goDown);
}

private function goDown(evt : Event) : void {
var acc_x : Number = (evt.target.center – evt.target.x) * SPRING;
evt.target.vel_x += acc_x;
evt.target.x += evt.target.vel_x;
evt.target.y += 15 – evt.target.vel_y;
evt.target.rotation++;
var sine : Number = Math.sin(evt.target.angle);
evt.target.scaleX = sine;
evt.target.angle += .1;
if(evt.target.y >= stage.stageHeight + 100) {
evt.target.removeEventListener(Event.ENTER_FRAME, goDown);
var m : MovieClip = evt.target as MovieClip;
removeChild(m);
}
}
}
// end class
}

Bước 3: Mở flash document

_ Mở library chọn movie “bg_mc” chọn linkage gõ vào mục class “com.FallenLeaves”

_ Kéo movieClip “bg_mc” ra Stage

Bước 4: Lưu lại Ctrl+Enter để test

Gửi phản hồi

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Thay đổi )

Twitter picture

You are commenting using your Twitter account. Log Out / Thay đổi )

Facebook photo

You are commenting using your Facebook account. Log Out / Thay đổi )

Connecting to %s

Follow

Get every new post delivered to your Inbox.