2021/9/11 15:25:38作者:佚名来源:网络
今天我们来讲解一个通过FLASH AS3来制作特酷的遮罩动画效果的教程,先看一下最终效果吧:
这里以FLASH CS4来讲解,具体制作步骤如下:
步骤一、打开FLASH CS4,新建一个FLASH文档,选择AS3,然后按Ctrl+J进行文档属性设置,把文档的高度、宽度分别设置为550×314(这个大小与背景图片大小相同),如图:

步骤二、导入作为背景图片,选中背景图片,按下【F8】,转为【影片剪辑】,名称填写【背景图】,这个名称你可以自己任意填写名称,点【确定】,如图所示:

接着对这个有背景图的图层进行锁定,如图:

步骤三、新建一个图层,取个名称遮罩层,然后椭圆工具画一个禁止笔触为50*50的圆,填充黑色(其实这里可以填充任何一种颜色),然后按F8,把这个圆转为影片剪辑,名称设为mask,如图所示:

步骤四、删除舞台中的这个圆,把该图层改名为AS。
步骤五、新建ActionScript文件,编写一个外部的MyMask.as文件。在编译器中输入代码如下:
package {
import flash.display.MovieClip;
public class MyMask extends MovieClip {
//Mask's x and y speed
public var speedX:Number;
public var speedY:Number;
//Set the given scale for this mask, when we create a new
//mask object
public function MyMask(scale:Number) {
this.scaleX = scale;
this.scaleY = scale;
}
}
}步骤六、转到flash中的as层,输入如下as代码:
//We use an array to hold all our masks.
//(Except the mask that follows our cursor)
var masks:Array = new Array();
//We add all of the masks to a container
var maskContainer:Sprite = new Sprite();
//Set the maskContainer to be the image's mask
backgroundImage.mask=maskContainer;
//Add the container on the stage
addChild(maskContainer);
//Create the mask which follows cursor movement (master mask)
var masterMask:MyMask=new MyMask(1);
//Set the master masks's coordinates to match cursor's coordinates
masterMask.x=mouseX;
masterMask.y=mouseY;
//Add the master mask to a container
maskContainer.addChild(masterMask);
//Cache the image and container as bitmap, so we
//can animate the alpha of the masks
maskContainer.cacheAsBitmap=true;
backgroundImage.cacheAsBitmap=true;
//Create a timer that is called every 0.2 seconds
var timer:Timer=new Timer(200,0);
timer.addEventListener(TimerEvent.TIMER, timerEvent);
timer.start();
//This function is called every 0.2 seconds.
//We create a new mask in this function.
function timerEvent(e:TimerEvent):void {
//Calculate a random scale for the new mask (0 to 1.5)
var scale:Number=Math.random()*1.5 + 0.5;
//Create a new mask with random scale
var newMask:MyMask=new MyMask(scale);
//Set the position for the new mask
newMask.x=mouseX;
newMask.y=mouseY;
//Assign a random x and y speed for the mask
newMask.speedX=Math.random()*20-10;
newMask.speedY=Math.random()*20-10;
//Add the mask to the container
maskContainer.addChild(newMask);
//Add the mask to the array
masks.push(newMask);
}
//We need ENTER_FRAME to animate the masks
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
//This function is called in each frame
function enterFrameHandler(e:Event):void {
//Loop through the mask array
for (var i:uint = 0; i < masks.length; i++) {
//Save a mask to a local variable
var myMask:MyMask = (MyMask)(masks[i]);
//Update the x and y position
myMask.x+=myMask.speedX;
myMask.y+=myMask.speedY;
//Increase the scale
myMask.scaleX+=0.1;
myMask.scaleY+=0.1;
//Reduce the alpha
myMask.alpha-=0.01;
//If the alpha is below 0, remove the mask
//from the container and from the array
if (myMask.alpha<0) {
masks.splice(i,1);
maskContainer.removeChild(myMask);
}
}
//Update the master mask position
masterMask.x=mouseX;
masterMask.y=mouseY;
}
至此,整个用AS3制作的特酷的遮罩动画效果动画就制作完成了,你可以按Ctrl+Enter进行测试。
感兴趣的朋友可以直接下载flash源码研究一下。
标签: as3 遮罩
相关文章
够快云库v6.3.24.12120免费版
详情
光影魔术手官方版 v4.7.1
详情
ADsafe净网大师v5.4.408.7000
详情
网易邮箱大师v5.3.2.1015电脑版
详情
foxmailv7.2.25.375
详情
暴风影音5v5.92.0824.1111
详情
暴风影音v5.92.0824.1111
详情
BitComet(比特彗星)v2.13.4.13Beta2
详情
路由优化大师v4.5.31.267
详情
茄子快传电脑版 v5.1.0.7
详情
搜狐影音 v7.2.1.0官方版
详情
搜狐影音客户端 v7.2.1.0
详情
迅雷影音官方版 v7.0.3.92
详情
cbox央视影音v6.0.3.4经典版
详情
potplayer播放器v1.7.22496
详情
Daum PotPlayer(已集成直播源)v1.7.22496绿色纯净美化便携增强版
详情
天国拯救2黄金版 Build.17149332-1.1.1.11377中文版
详情
燕云十六声电脑版 v1.9.31
详情
潜行者2:切尔诺贝利之心 Build.16805297豪华中文版
详情
模拟农场25豪华中文版
详情
迷你世界电脑版 v1.41.00
详情
骑马与砍杀2 v1.2.9.34019免费版
详情
侠盗猎车手圣安地列斯 v1.0最新中文版
详情
整蛊白云 v1.0
详情
地平线4 v1.476中文版
详情
圣女战旗中文v1.1.9绿色免安装版
详情
狂怒2中文
详情
红色警戒2共和国之辉电脑版 v1.0
详情
模拟人生4 v1.0中文免费版
详情
蛊婆v1.0免费版
详情
风起云涌2越南中文版 v1.6Steam正版
详情
使命召唤17官方中文版 v1.0
详情
途家民宿v9.14.6安卓版
详情
松鼠记账v6.8.1安卓版
详情
掌门好家长v5.10.0手机版
详情
惠买v5.4.46官方版
详情
快快查汉语字典综合官方版V5.0.0官方版
详情
尚德机构v7.8.1官方版
详情
头像精灵v3.7.0美化版
详情
运满满货主版v7.92.1.0安卓版
详情
运满满司机版app手机版v8.92.1.0安卓版
详情
网易蜗牛读书水墨版V1.9.78
详情
泼辣修图免费版v6.11.3安卓版
详情
泼辣修图安卓版v6.11.3
详情
汽车大师v7.15.5技师版
详情
步多多v2.8.1安卓版
详情
新浪新闻v8.43.7官方版
详情
拓词v14.21安卓版
详情