Bài tập này sẽ hướng dẫn bạn tạo một hình gradient màu bằng cách di chuyển chuột, sử dụng Action Script trong Flash 8. Bước 1 Bước 2 import flash.filters.GradientBevelFilter; Bước 3 import flash.filters.GradientBevelFilter; bao gồm các bộ lọc var shapeClip:MovieClip = this.createEmptyMovieClip("shape_mc", 1); để tạo Movie Clip với tên tương ứng shape_mc xác định kích cỡ của movie shapeClip._x = (Stage.width - shapeClip._width) / 2; để tạo hình dạng var colors:Array = new Array(0xFFFFFF, 0xCCCCCC, 0x000000); thiết lập màu sắc var alphas:Array = new Array(1, 0, 1); thiết lập góc var ratios:Array = new Array(0, 128, 255); thiết lập kích thước var gradientBevel:GradientBevelFilter = new GradientBevelFilter(10, 45, colors, alphas, ratios, 4, 4, 5, 3); Bao gồm bộ lọc góc xiên của hình gradient và thiết lập alpha với kích cỡ. var mouseListener:Object = new Object(); Xác định hàm cho chuột di chuyển. Tải về file nguồn.
Tạo một file flash mới, nhấn Ctrl + R trên bàn phím (Document Properties), thiết lập Width và Height đều bằng 200px
Chọn frame đầu tiên, mở Action Script Pannel (F9) và đưa vào đoạn script sau:
var shapeClip:MovieClip = this.createEmptyMovieClip("shape_mc", 1);
shape_mc
with (shapeClip) {
beginFill(0xFF0000, 100);
moveTo(0, 0);
lineTo(200, 0);
lineTo(200, 200);
lineTo(0, 200);
lineTo(0, 0);
endFill();
}
shapeClip._x = (Stage.width - shapeClip._width) / 2;
shapeClip._y = (Stage.height - shapeClip._height) / 2;
var colors:Array = new Array(0xFFFFFF, 0xCCCCCC, 0x000000);
var alphas:Array = new Array(1, 0, 1);
var ratios:Array = new Array(0, 128, 255);
var gradientBevel:GradientBevelFilter = new GradientBevelFilter(10, 45, colors, alphas, ratios, 4, 4, 5, 3);
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
gradientBevel.strength++;
shapeClip.filters = [gradientBevel];
};
mouseListener.onMouseMove = function() {
gradientBevel.blurX = (_xmouse / Stage.width) * 255;
gradientBevel.blurY = (_ymouse / Stage.height) * 255;
shapeClip.filters = [gradientBevel];
};
Mouse.addListener(mouseListener);
Giải thích từng đoạn script
Đoạn này
Đoạn này
Đoạn này
with (shapeClip) {
beginFill(0xFF0000, 100);
moveTo(0, 0);
lineTo(200, 0);
lineTo(200, 200);
lineTo(0, 200);
lineTo(0, 0);
endFill();
}
Đoạn này
shapeClip._y = (Stage.height - shapeClip._height) / 2;
Đoạn này
Đoạn này
Đoạn này
Đoạn này
Đoạn này
mouseListener.onMouseDown = function() {
gradientBevel.strength++;
shapeClip.filters = [gradientBevel];
};
mouseListener.onMouseMove = function()
Đăng nhận xét