给大家简单介绍一下Flash中使用AS来画线,从下面这个函数开始吧! _root.createEmptyMovieClip("terrain", 1);
这个函数的功能是创建一个空的MC,名字为terrain。然后开始画线
:_root.terrain.lineStyle(10, 0xff0000, 100);
10代表线的粗细;0xff0000代表线颜色;100代表线的alpha为100。你可以查看一下手册lineStyle函数的使用。下面开始具体给出画线的代码:
画红色矩形:
createEmptyMovieClip("terrain", 1);
terrain.lineStyle(10, 0xff00ff, 100);
terrain.moveTo(100, 100);
terrain.lineTo(300, 100);
terrain.lineTo(300, 300);
terrain.lineTo(100, 300);
terrain.lineTo(100, 100);
效果:
鼠标画线:
createEmptyMovieClip("terrain", 1);
terrain.lineStyle(10, 0xff00ff, 100);
onEnterFrame = function () {
terrain.lineTo(_xmouse, _ymouse);
};
效果:
改变帧频为50fps。
只有按一下鼠标才能画:
createEmptyMovieClip("terrain", 1);
terrain.lineStyle(10, 0xff00ff, 100);
imdrawing = false;
onMouseDown = function () {
if (imdrawing == false) {
terrain.moveTo(_xmouse, _ymouse);
imdrawing = true;
}
if (imdrawing == true) {
onEnterFrame = function () {
terrain.lineTo(_xmouse, _ymouse);
};
}
};
onMouseUp = function () {
onEnterFrame = function () {
imdrawing = false;
};
};
效果:
添加一些其它的画线效果:
import flash.filters.BevelFilter;
var distance:Number = 2;
var angleInDegrees:Number = 45;
var highlightColor:Number = 0xff00ff;
var highlightAlpha:Number = 1;
var shadowColor:Number = 0xbb00bb;
var shadowAlpha:Number = 1;
var blurX:Number = 8;
var blurY:Number = 8;
var strength:Number = 10;
var quality:Number = 3;
var type:String = "inner";
var knockout:Boolean = false;
var my_bevel_filter:BevelFilter = new BevelFilter(distance, angleInDegrees, highlightColor, highlightAlpha, shadowColor,
shadowAlpha, blurX, blurY, strength, quality, type, knockout);
createEmptyMovieClip("terrain", 1);
terrain.lineStyle(20, 0xdd00dd, 100);
terrain.filters = new Array(my_bevel_filter);
imdrawing = false;
onMouseDown = function () {
if (imdrawing == false) {
terrain.moveTo(_xmouse, _ymouse);
imdrawing = true;
}
if (imdrawing == true) {
onEnterFrame = function () {
terrain.lineTo(_xmouse, _ymouse);
};
}
};
onMouseUp = function () {
onEnterFrame = function () {
imdrawing = false;
};
};
效果:
模糊效果画线:
import flash.filters.BlurFilter;
var blurX:Number = 30;
var blurY:Number = 30;
var quality:Number = 3;
var my_blur_filter:BlurFilter = new BlurFilter(blurX, blurY, quality);
createEmptyMovieClip("terrain", 1);
terrain.lineStyle(20, 0xdd00dd, 100);
terrain.filters = new Array(my_blur_filter);
imdrawing = false;
onMouseDown = function () {
if (imdrawing == false) {
terrain.moveTo(_xmouse, _ymouse);
imdrawing = true;
}
if (imdrawing == true) {
onEnterFrame = function () {
terrain.lineTo(_xmouse, _ymouse);
};
}
};
onMouseUp = function () {
onEnterFrame = function () {
imdrawing = false;
};
};
效果:
发光效果画线代码:
import flash.filters.GlowFilter;
var color:Number = 0x33CCFF;
var alpha:Number = .8;
var blurX:Number = 35;
var blurY:Number = 35;
var strength:Number = 2;
var quality:Number = 3;
var inner:Boolean = false;
var knockout:Boolean = false;
var my_glow_filter:GlowFilter = new GlowFilter(color, alpha, blurX, blurY, strength, quality, inner, knockout);
createEmptyMovieClip("terrain", 1);
terrain.lineStyle(20, 0xdd00dd, 100);
terrain.filters = new Array(my_glow_filter);
imdrawing = false;
onMouseDown = function () {
if (imdrawing == false) {
terrain.moveTo(_xmouse, _ymouse);
imdrawing = true;
}
if (imdrawing == true) {
onEnterFrame = function () {
terrain.lineTo(_xmouse, _ymouse);
};
}
};
onMouseUp = function () {
onEnterFrame = function () {
imdrawing = false;
};
};
效果:
画阴影线的代码:
import flash.filters.DropShadowFilter;
var distance:Number = 20;
var angleInDegrees:Number = 45;
var color:Number = 0x000000;
var alpha:Number = .8;
var blurX:Number = 16;
var blurY:Number = 16;
var strength:Number = 1;
var quality:Number = 3;
var inner:Boolean = false;
var knockout:Boolean = false;
var hideObject:Boolean = false;
var my_shadow_filter:DropShadowFilter = new DropShadowFilter(distance, angleInDegrees, color, alpha, blurX, blurY, strength, quality, inner, knockout, hideObject);
createEmptyMovieClip("terrain", 1);
terrain.lineStyle(20, 0xdd00dd, 100);
terrain.filters = new Array(my_shadow_filter);
imdrawing = false;
onMouseDown = function () {
if (imdrawing == false) {
terrain.moveTo(_xmouse, _ymouse);
imdrawing = true;
}
if (imdrawing == true) {
onEnterFrame = function () {
terrain.lineTo(_xmouse, _ymouse);
};
}
};
onMouseUp = function () {
onEnterFrame = function () {
imdrawing = false;
};
};
效果:
上面所有效果都混合在一起:
// bevel filter
import flash.filters.BevelFilter;
var distance:Number = 5;
var angleInDegrees:Number = 45;
var highlightColor:Number = 0xFFFF00;
var highlightAlpha:Number = .8;
var shadowColor:Number = 0x0000FF;
var shadowAlpha:Number = .8;
var blurX:Number = 5;
var blurY:Number = 5;
var strength:Number = 5;
var quality:Number = 3;
var type:String = "inner";
var knockout:Boolean = false;
var my_bevel_filter:BevelFilter = new BevelFilter(distance, angleInDegrees, highlightColor, highlightAlpha, shadowColor,
shadowAlpha, blurX, blurY, strength, quality, type, knockout);
// blur filter
import flash.filters.BlurFilter;
var blurX:Number = 30;
var blurY:Number = 30;
var quality:Number = 3;
var my_blur_filter:BlurFilter = new BlurFilter(blurX, blurY, quality);
// shadow
import flash.filters.DropShadowFilter;
var distance:Number = 20;
var angleInDegrees:Number = 45;
var color:Number = 0x000000;
var alpha:Number = .8;
var blurX:Number = 16;
var blurY:Number = 16;
var strength:Number = 1;
var quality:Number = 3;
var inner:Boolean = false;
var knockout:Boolean = false;
var hideObject:Boolean = false;
var my_shadow_filter:DropShadowFilter = new DropShadowFilter(distance, angleInDegrees, color, alpha, blurX, blurY, strength, quality, inner, knockout, hideObject);
// glow
import flash.filters.GlowFilter;
var color:Number = 0x33CCFF;
var alpha:Number = .8;
var blurX:Number = 35;
var blurY:Number = 35;
var strength:Number = 2;
var quality:Number = 3;
var inner:Boolean = false;
var knockout:Boolean = false;
var my_glow_filter:GlowFilter = new GlowFilter(color, alpha, blurX, blurY, strength, quality, inner, knockout);
_root.createEmptyMovieClip("terrain", 1);
_root.terrain.lineStyle(10, 0xff00ff, 100);createEmptyMovieClip("terrain", 1);
terrain.lineStyle(20, 0xdd00dd, 100);
terrain.filters = new Array(my_shadow_filter,my_glow_filter,my_blur_filter,my_bevel_filter);
imdrawing = false;
onMouseDown = function () {
if (imdrawing == false) {
terrain.moveTo(_xmouse, _ymouse);
imdrawing = true;
}
if (imdrawing == true) {
onEnterFrame = function () {
terrain.lineTo(_xmouse, _ymouse);
};
}
};
onMouseUp = function () {
onEnterFrame = function () {
imdrawing = false;
};
};
效果: