一、形状类Shape
1.创建Shape类对象,调用其graphics属性,在调用其相应的方法进行绘制即可。
二、对对象应用动态遮罩
1.使用遮罩需要明白三点,1)需要被遮罩的显示对象(谁要被遮罩),2)作为遮罩的显示对象(拿什么遮罩),3)将作为遮罩的显示对象赋值给需要被遮罩的显示对象的mask属性。
三、使用ActionScript创建可视化效果
1.混合模式类:BlendMode
2.动态滤镜 :DropShadowFilter阴影滤镜 BlurFilter模糊滤镜
下面贴出极端flash中写的actionscript的代码,希望对大家有帮助:
1.形状类的使用
import flash.display.Shape;
//绘制矩形和圆角矩形
/*var rect:Shape = new Shape();
rect.graphics.beginFill(0xff0000);
rect.graphics.lineStyle(1,0x000000);
//rect.graphics.drawRect(0,0,100,200);//绘制矩形
rect.graphics.drawRoundRect(0,0,100,200,20);//绘制圆角矩形
rect.graphics.endFill();
addChild(rect);*/
//绘制圆形
var circle:Shape = new Shape();
var radius:uint = 75;
circle.graphics.beginFill(0xff0000);
circle.graphics.lineStyle(1,0x000000);
circle.graphics.drawCircle(0+radius,0+radius,radius);
circle.graphics.endFill();
addChild(circle);
2.遮罩和混合的使用(两者建议别同时使用)
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.display.Shape;
//从外部加载图片,为图片进行遮罩,使图片变成圆角
var imageLoader:Loader = new Loader();
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
imageLoader.load(new URLRequest("http://www.focusonmedia.com/vqs/as3/cheese_and_crackers.jpg"));
function completeHandler(evt:Event):void{
var roundRect:Shape = new Shape();
roundRect.graphics.beginFill(0xff0000);
roundRect.graphics.lineStyle(0,0x000000);
roundRect.graphics.drawRoundRect(imageLoader.x,imageLoader.y,imageLoader.width,imageLoader.height,20);
roundRect.graphics.endFill();
addChild(imageLoader);
addChild(roundRect);
// roundRect.blendMode = BlendMode.MULTIPLY;//混合模式使用
imageLoader.mask = roundRect;//遮罩的使用
}
3.滤镜的使用
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.display.Shape;
import flash.display.BlendMode;
import flash.filters.BlurFilter;
import flash.filters.DropShadowFilter;
//从外部加载图片,为图片进行遮罩,使图片变成圆角
var imageLoader:Loader = new Loader();
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
imageLoader.load(new URLRequest("http://www.focusonmedia.com/vqs/as3/cheese_and_crackers.jpg"));
function completeHandler(evt:Event):void{
var blurFilter:BlurFilter = new BlurFilter(20,0,10);
imageLoader.filters = [blurFilter];
addChild(imageLoader);
}
var roundShope:Shape = new Shape();
roundShope.graphics.beginFill(0x0000ff);
roundShope.graphics.lineStyle(1,0x000fff);
roundShope.graphics.drawRoundRect(50,50,100,35,15);
roundShope.graphics.endFill();
var dropShawFilter:DropShadowFilter = new DropShadowFilter(5,45,0x000000,.25,20,20,3);
roundShope.filters = [dropShawFilter];
roundShope.blendMode = BlendMode.MULTIPLY;
addChild(roundShope);