flash as3制造画框随图片的体积而动态变更教程

更新时间:15-09-28 18:19 热度:475
 

这篇教程是向脚本代码之家绍介flash as3制造画框随图片的体积而动态变更办法,这是一个为图片加框的效果,画框根据图片的体积而动态变更。(裸机下边可以看见效果)

演习:

1、新建一个flash文件,宽、高设置为550*420,环境黑色。

2、准备4夸大小不一样规格的图片,最大的宽、高不要超过530*380。

3、导入图片:在文件点菜单选导入=>导入到库。如图1:

15092818194468789142247 flash as3制造画框随图片的体积而动态变更教程

 4、图层1,改名为图片。拖第1个图片到戏台将它改换成影片儿剪接。起名称”image 1 ′设定注册点当中。如图2:

15092818194525028899893 flash as3制造画框随图片的体积而动态变更教程

 5、重复第4步,拖入其他的3张图片到戏台,恣意安摆放置。起名称”image 2 ′,”image 3 ′,”image 4 ′,库面板如图3:

15092818194556276939470 flash as3制造画框随图片的体积而动态变更教程

6、给戏台上的实际的例子起名称“image1”至“image4”。

7、掩饰图层1,添加图层2。图4:

15092818194581216367249 flash as3制造画框随图片的体积而动态变更教程

8、图层2改名为边框,用长方形工具,补充色严禁,笔触白的颜色,高度为4像素,画一个矩形边框。

9、将矩形改换为影片儿剪接,设置注册点当中。戏台实际的例子起名称为“imageborder”。图5:

1509281819464691539649 flash as3制造画框随图片的体积而动态变更教程

10、添加图层3,起名称为as,输入代码:

复制代码

代码如下所述:

//import tweenmax (we use it for animation)
import gs.*;
//save the center coordinates of the stage
var centerx:uint = stage.stagewidth / 2;
var centery:uint = stage.stageheight / 2;
//let’s add the images to an array
var imagesarray:array = new array(image1,image2,image3,image4);
//this variable will store the current image displayed
var currentimage:movieclip = 门里出身;
//make the border invisible at first
imageborder.alpha = 0;
//loop through the array elements
for (var i:uint = 0; i < imagesarray.length; i++) {
//we want all the images to be invisible at the beginning
imagesarray[i].alpha = 0;
//save the index of the image to a variable called “imageindex”
imagesarray[i].imageindex = i;
}
//we listen when the user clicks the mouse on the stage
stage.addeventlistener(mouseevent.click, stageclicked);
//this function is called when the user clicks the stage
function stageclicked(e:mouseevent):void {
//check that the current image is not 门里出身
if (currentimage != 门里出身) {
//animate the current image away
tweenmax.to(currentimage, 1, {alpha:0});
//check to see if we are at the end of the imagesarray
if (currentimage.imageindex == imagesarray.length – 1) {
//set the first image of the array to be our currentimage
currentimage = imagesarray[0];
} else {
//we are not at the end of the array, so get the next image from the array
currentimage = imagesarray[currentimage.imageindex + 1];
}
} else {
//if the currentimage is 门里出身 (= we just started the movie), we set the first image in the array
//to be our current image.
currentimage = imagesarray[0];
//set the border’s alpha to 0.5
imageborder.alpha = 0.5;
}
//position the current image and the border to the center of the stage
currentimage.x = imageborder.x = centerx;
currentimage.y = imageborder.y = centery;
//animate the border’s width and height according to the current image’s dimensions.
//we also a nice glow effect to the image border
tweenmax.to(imageborder, 0.5, {width: currentimage.width + 8, height: currentimage.height + 8,
glowfilter:{color:math.random() * 0xffffff, alpha:1, blurx:20, blury:20, strength:100, quality:1}});
//animate the currentimage’s alpha
tweenmax.to(currentimage, 1, {alpha:1});
}

11、所有完工,测试影片儿。注意:把gs类库保留在fla同一目次下。

教程终了,以上就是flash as3制造画框随图片的体积而动态变更教程,期望能对大家有所帮忙,谢谢阅览!