Flash AS3制作畫框隨圖片的大小而動(dòng)態(tài)改變教程

這篇教程是向腳本之家介紹Flash AS3制作畫框隨圖片的大小而動(dòng)態(tài)改變方法,這是一個(gè)為圖片加框的效果,畫框依據(jù)圖片的大小而動(dòng)態(tài)改變。(單擊下面可以看到效果)
演示:
1、新建一個(gè)Flash文件,寬、高設(shè)置為550*420,背景黑色。
2、準(zhǔn)備4張大小不同規(guī)格的圖片,最大的寬、高不要超過530*380。
3、導(dǎo)入圖片:在文件菜單選導(dǎo)入=>導(dǎo)入到庫(kù)。如圖1:
4、圖層1,改名為圖片。拖第一個(gè)圖片到舞臺(tái)將它轉(zhuǎn)換成影片剪輯。命名”Image 1 ″設(shè)定注冊(cè)點(diǎn)居中。如圖2:
5、重復(fù)第4步,拖入其它的3張圖片到舞臺(tái),任意擺放。命名”Image 2 ″,”Image 3 ″,”Image 4 ″,庫(kù)面板如圖3:
6、給舞臺(tái)上的實(shí)例命名“image1”至“image4”。
7、隱藏圖層1,添加圖層2。圖4:
8、圖層2改名為邊框,用矩形工具,填充色禁止,筆觸白色,高度為4像素,畫一個(gè)長(zhǎng)方形邊框。
9、將長(zhǎng)方形轉(zhuǎn)換為影片剪輯,設(shè)置注冊(cè)點(diǎn)居中。舞臺(tái)實(shí)例命名為“imageBorder”。圖5:
10、添加圖層3,命名為as,輸入代碼:
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});
}
教程結(jié)束,以上就是Flash AS3制作畫框隨圖片的大小而動(dòng)態(tài)改變教程,希望能對(duì)大家有所幫助,謝謝閱讀!
相關(guān)文章
flash如何做雨滴下落的動(dòng)畫效果? Flash8做一個(gè)下雨效果的技巧
flash如何做雨滴下落的動(dòng)畫效果?想要做一個(gè)逼真的雨滴落下的效果,該怎么做雨滴落下水花擴(kuò)散的效果呢?下面我們就來看看Flash8做一個(gè)下雨效果的技巧2022-08-18flash理發(fā)店旋轉(zhuǎn)彩燈動(dòng)畫效果怎么做? 理發(fā)店旋轉(zhuǎn)燈制作技巧
flash理發(fā)店旋轉(zhuǎn)彩燈動(dòng)畫效果怎么做?經(jīng)常使用flash制作動(dòng)畫效果,該怎么制作旋轉(zhuǎn)燈效果,下面我們就來看看理發(fā)店旋轉(zhuǎn)燈制作技巧,詳細(xì)請(qǐng)看下文介紹2022-07-23flash怎么把形狀變成文字? flash星星變文字動(dòng)畫的實(shí)現(xiàn)方法
flash怎么把形狀變成文字?flash繪制的星星想要慢慢變成文字,該怎么將圖形變文字呢?下面我們就來看看flash星星變文字動(dòng)畫的實(shí)現(xiàn)方法,詳細(xì)請(qǐng)看下文介紹2022-06-06flash怎么制作補(bǔ)間動(dòng)畫? flash變形動(dòng)畫的實(shí)現(xiàn)方法
flash怎么制作補(bǔ)間動(dòng)畫?flash中想要制作形狀變化的動(dòng)畫效果,該怎么制作補(bǔ)間動(dòng)畫呢?下面我們就來就來看看flash變形動(dòng)畫的實(shí)現(xiàn)方法2022-02-06FLASH怎么讓搖曳的荷花更逼著? flash制作風(fēng)吹荷花動(dòng)畫的技巧
FLASH怎么讓搖曳的荷花更逼?flash中想要制作風(fēng)吹荷花的動(dòng)畫熊愛國(guó),該怎么制作這個(gè)效果呢?下面我們就來看看flash制作風(fēng)吹荷花動(dòng)畫的技巧2022-02-06flash怎么制作荷花在荷花池里搖擺的動(dòng)畫? FLASH做擺動(dòng)荷花的技巧
flash怎么制作荷花在荷花池里搖擺的動(dòng)畫??flash中想要制作荷花搖擺的動(dòng)畫,該怎么制作荷花搖曳的動(dòng)畫呢?下面我們就來看看FLASH做擺動(dòng)荷花的技巧2022-02-06flash怎么做徑向彩虹文字動(dòng)畫? 文字添加彩虹動(dòng)畫效果的技巧
flash怎么做徑向彩虹文字動(dòng)畫?flash椎間盤買個(gè)輸入的文字,想要添加動(dòng)畫效果,該怎么添加徑向彩虹文字效果呢?下面我們就來看看flash文字添加彩虹動(dòng)畫效果的技巧,詳細(xì)請(qǐng)2021-11-09flash怎么做眨眼動(dòng)畫效果? flash動(dòng)漫人物眨眼動(dòng)畫的做法
flash怎么做眨眼動(dòng)畫效果?flash中想要制作一個(gè)動(dòng)漫人物的眼睛眨眼動(dòng)畫,該怎么制作呢?下面我們就來看看flash動(dòng)漫人物眨眼動(dòng)畫的做法2021-11-08flash怎么制作火焰文字效果? flash做火焰字體動(dòng)畫的技巧
flash怎么制作火焰文字效果?flash中想要制作一個(gè)熊熊燃燒的活顏文字,該怎么制作這個(gè)文字效果呢?下面我們就來看看flash做火焰字體動(dòng)畫的技巧2021-11-01flash怎么做文字動(dòng)畫logo? 閃動(dòng)的片頭動(dòng)畫flash的實(shí)現(xiàn)方法
flash怎么做文字動(dòng)畫logo?flash中想要制作一個(gè)文字logo的動(dòng)畫,讓文字閃爍,該怎么制作這個(gè)效果呢?下面我們就來看看flash制作文字動(dòng)畫的技巧2021-10-29