flash 雪花飘代码
flash 雪花飘代码
好现来看效果图片.
var sceneWidth = sceneHeight=300;
var sideDisWidth = Stage.width/2-sceneWidth/2;
var sideDisHeight = Stage.height/2-sceneHeight/2;
var snowNum = 80;
var snowSpace:MovieClip = _root.createEmptyMovieClip("room", 1);
function addMasker() {
_root.createEmptyMovieClip("masker", 10000);
with (masker) {
beginFill(0x000550, 100);
moveTo(sideDisWidth, sideDisHeight);
lineTo(sideDisWidth+sceneWidth, sideDisHeight);
lineTo(sideDisWidth+sceneWidth, sideDisHeight+sceneHeight);
lineTo(sideDisWidth, sideDisHeight+sceneHeight);
lineTo(sideDisWidth, sideDisHeight);
endFill();
}
snowSpace.setMask(masker);
createSnow();
}
function snowProperty(snow, w, h) {
snow._x = sideDisWidth+Math.random()*w;
snow._y = sideDisHeight+Math.random()*h;
snow._rotation = Math.random()*120+30;
snow.stepX = Math.cos((snow._rotation*Math.PI)/180);
snow.stepY = Math.random()*2+1;
setInterval(snowFall, 30, snow);
}
function drawSnow(snow:MovieClip, radius:Number) {
var p = radius*.9;
with (snow) {
colors = [0xCCCCCC, 0xFFFFFF];
alphas = [100, 100];
ratios = [0, 255];
matrix = {matrixType:"box", x:-Math.random()*2*radius, y:-Math.random()*2*radius, w:2*radius, h:2*radius, r90/180)*Math.PI};
beginGradientFill("radial", colors, alphas, ratios, matrix);
moveTo(0, -radius);
curveTo(p, -p, radius, 0);
curveTo(p, p, 0, radius);
curveTo(-p, p, -radius, 0);
curveTo(-p, -p, 0, -radius);
endFill();
}
snowProperty(snow, sceneWidth, sceneHeight);
}
function createSnow() {
var n = 0;
while (n<snowNum) {
var snow:MovieClip = snowSpace.createEmptyMovieClip("s"+n, n);
var radius:Number = Math.random()*3;
drawSnow(snow, radius);
n++;
}
}
function snowFall(snow) {
snow._x += snow.stepX;
snow._y += snow.stepY;
if (snow._x<sideDisWidth) {
snow._x = sideDisWidth+sceneWidth;
}
if (snow._x>sideDisWidth+sceneWidth) {
snow._x = sideDisWidth;
}
if (snow._y>sideDisHeight+sceneHeight) {
snow._y = sideDisHeight;
}
}
addMasker();
_root.createEmptyMovieClip("myMC", 10);
with (myMC) {
lineStyle(1, 0xcccccc, 100);
moveTo(sideDisWidth, sideDisHeight);
lineTo(sideDisWidth+sceneWidth, sideDisHeight);
lineTo(sideDisWidth+sceneWidth, sideDisHeight+sceneHeight);
lineTo(sideDisWidth, sideDisHeight+sceneHeight);
lineTo(sideDisWidth, sideDisHeight);
var infor:TextField = myMC.createTextField("infor", 1, sideDisWidth+sceneWidth-100, sideDisHeight+sceneHeight, 100, 20);
infor.autoSize="right";
infor.selectable=false;
infor.textColor = 0xcccccc;
infor.text = "by holybozo";
}
_root.createEmptyMovieClip("bg", -1);
with (bg) {
beginFill(0x999999, 100);
moveTo(0, 0);
lineTo(Stage.width, 0);
lineTo(Stage.width, Stage.height);
lineTo(0, Stage.height);
lineTo(0, 0);
endFill();
}
补充:flash教程,Action