Flash AS3制作画框随图片的大小而动态改变教程

所属分类: 媒体动画 / Flash教程 阅读数: 52
收藏 0 赞 0 分享

这篇教程是向脚本之家介绍Flash AS3制作画框随图片的大小而动态改变方法,这是一个为图片加框的效果,画框依据图片的大小而动态改变。(单击下面可以看到效果)

演示:

1、新建一个Flash文件,宽、高设置为550*420,背景黑色。

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

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

sshot-1.png

 4、图层1,改名为图片。拖第一个图片到舞台将它转换成影片剪辑。命名”Image 1 ″设定注册点居中。如图2:

sshot-2.png

 5、重复第4步,拖入其它的3张图片到舞台,任意摆放。命名”Image 2 ″,”Image 3 ″,”Image 4 ″,库面板如图3:

sshot-3.png

6、给舞台上的实例命名“image1”至“image4”。

7、隐藏图层1,添加图层2。图4:

sshot-4.png


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

9、将长方形转换为影片剪辑,设置注册点居中。舞台实例命名为“imageBorder”。图5:

sshot-5.png

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 = null;
//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 null
if (currentImage != null) {
//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 null (= 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制作画框随图片的大小而动态改变教程,希望能对大家有所帮助,谢谢阅读!
更多精彩内容其他人还在看

Flash cs3绘制人物高级行走动画教程

本教程向大家介绍Flash cs3绘制人物高级行走动画效果,教程难度不是很大,绘制方法及过程介绍的也非常详细,教程很实用,转发过来,希望大家喜欢
收藏 0 赞 0 分享

Flash CS4来制作漂亮的气泡动画教程

本教程向脚本之家的朋友介绍用Flash CS4来制作漂亮的气泡动画,制作出来气泡真的很好看,制作效果是采用代码形式实现,觉得很不错,转发过来,感兴趣的朋友可以一起来学习
收藏 0 赞 0 分享

flash基础教程:帧、关键帧、空白帧概念及区别介绍

动画的产生是帧来实现的,那什么是帧?帧、关键帧和空白帧之间又有什么区别?本文就为大家介绍一下三者之间的关系
收藏 0 赞 0 分享

Flash教程:动画背景的绘制方法之透视篇(给新手)

Flash动画在网络上的广泛传播,已经成为上网一族喜闻乐见的一种艺术形式。动画背景的绘制方法有很多,也有很多表现方法。这里将结合透视学的基础知识向大家简单的介绍一下动画背景的绘制。
收藏 0 赞 0 分享

Flash AS入门教程:Flash AS3.0制作有年份有日期的时钟

本教程是向大家介绍利用Flash AS3.0制作有年份有日期的时钟,虽然制作时钟老套了点,但它确可以较全面地应用到时间日期和间隔等知识,仍不失为较好的入门练习,转发给大家,希望对大家有所帮助
收藏 0 赞 0 分享

Flash相册制作大师具体该如何使用 Flash相册制作大师使用教程

在本文中我们将会看到的是Flash相册制作大师的具体使用的方法
收藏 0 赞 0 分享

flash基础教程:混色器面板图文介绍

混色器面板是Flash中用于色彩处理的一个重要面板,熟练地使用该面板,可以帮助用户快速地完成色彩的填充,编辑出色彩丰富的图形。本教程为大家详细介绍一下混色器面板,希望对大家有所帮助
收藏 0 赞 0 分享

25个绝对让你应接不暇的Flash网站创意

在Web设计过程中,运用成熟的Flash技术可以把你任意想到的idea表现到产品页面中。这里为你整理发现了25个绝对让你应接不暇的 Flash网站创意,更好地体现网站的互动应用,同时可以让你大饱眼福,一起来欣赏吧
收藏 0 赞 0 分享

教你用Flash制作非常酷的二进制时钟动画

今天在这个教程中我们将学习用Flash做一个不同寻常的,但非常酷的时钟:一个二进制时钟,中间用到了代码,但介绍地很详细,相信很值得大家学习
收藏 0 赞 0 分享

Flash动画特效制作技巧:制作超酷的文字炸开动画效果

本教程向大家介绍Flash动画特效制作技巧,本实例是制作文字炸开的动画效果,制作效果非常酷,制作过程也比较简单,喜欢的朋友可以过来学习一下这种制作方法
收藏 0 赞 0 分享
查看更多