Link:INB Home|INB English| INB русский язык|INB العربية|INB Türkiye|INB فارسی|INB Español|INB Français|INB Português|INB Deutsch|INB 國語|INB 中文|INB 日本语|INB 한국어|INB ภาษาไทย|INB tiếng Việt||[FL]Flash Tutorial Revealing an Image with a Grid Effect Animation
INB English forum
Welcome to (Industry & Native boffin) The industrial age here is full of fighting spirit, you and I both through this network space with Native biological spirit boffin came to the mad labs. home INBforum.com, come and join us Permanent name: inb-english.forumotion.com
INB English forum
Welcome to (Industry & Native boffin) The industrial age here is full of fighting spirit, you and I both through this network space with Native biological spirit boffin came to the mad labs. home INBforum.com, come and join us Permanent name: inb-english.forumotion.com
INB English forum

Welcome to (Industry & Native boffin) The industrial age here is full of fighting spirit, you and I both through this network space with Native biological spirit boffin came to the mad labs. home INBforum.com, Permanent name: inb-english.forumotion.com


You are not connected. Please login or register

《《《《《《《上一页INBforum   Go down

上一页INBforum》》》》》》》View previous topic View next topic Go down  Message [Page 1 of 1]

1[FL]Flash Tutorial Revealing an Image with a Grid Effect Animation Empty [FL]Flash Tutorial Revealing an Image with a Grid Effect Animation Wed Sep 22, 2010 11:07 am

Admin

Admin
Admin
1. Create a new flash file (Actionscript 3.0) and save it as grid.fla.
2. All will happen in the code so open the actions panel. As often, we’ll use the Tweenlite engine.
First import the Tweenlite engine.view source

print?


1import com.greensock.*;



3. Declare 2 constants to store the number of columns and rows that you like the image to be sliced into, and an Array variable to stores later all the sliced images.view source

print?


1const COLUMNS:uint=10;

2const ROWS:uint=10;

3

4var gridImages : Array = new Array();



4. Next load the image. When the image is loaded, it will call the onImageLoaded function.view source

print?


1var imageLoader:Loader = new Loader();

2imageLoader.load(new URLRequest("myImage.jpg"));

3imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);



5. In the onImageLoaded function, we want to slice the images into COLUMNS*ROWS pieces.
First we retrieve the bitmap data of the loaded image. Store the width and the height of a piece.
Then we loop through the columns and through the rows. Inside this double loop, we create for each iteration a movie clip (imageHolder) that will contain a piece of the original image. The small piece is created by using the copyPixels() method that copies a rectangular area from the original image into the small piece. We set the imageHolder’s x and y properties and set its alpha property to 0 to make it invisible.
We add the imageHolder to the gridImages array and add it to the display list.
Finally when all our sliced images have been created we call the revealImage() function that we’re going to create right now.view source

print?


01function onImageLoaded(e:Event):void {

02

03 var originalBitmapData:BitmapData = e.target.content.bitmapData;

04

05 var imageWidth : Number = originalBitmapData.width / COLUMNS;

06 var imageHeight : Number = originalBitmapData.height / ROWS;

07

08 for (var i = 0; i < COLUMNS; i++) {

09

10 for (var j = 0; j < ROWS; j++) {

11

12 var imageHolder:MovieClip = new MovieClip();

13

14 var image:Bitmap = new Bitmap();

15 image.bitmapData=new BitmapData(imageWidth,imageHeight);

16 image.bitmapData.copyPixels(

17 originalBitmapData,

18 new Rectangle(i * imageWidth, j * imageHeight,imageWidth, imageHeight),

19 new Point(1,1));

20

21 imageHolder.addChild(image);

22

23 imageHolder.x=i*imageWidth;

24 imageHolder.y=j*imageHeight;

25 imageHolder.alpha=0;

26

27 imagesGrid.push(imageHolder);

28 addChild(imageHolder);

29 }

30 }

31

32 revealImage();

33}



6. The revealImage() function loop through the imagesGrid array and for each image uses the Tweenlite engine to animate its alpha property. We specify the delay parameter to make the pieces of the original image appear one after another.view source

print?


1function revealImage():void{

2 for (var i:int = 0; i < imagesGrid.length; i++){

3 var imageGrid:MovieClip = imagesGrid as MovieClip;

4 TweenLite.to(imageGrid, .5, { alpha: 1,delay:i*.15});

5 }

6}



[i]7. Here’s the final code. Test your movie to see it in action.view source

print?


01import com.greensock.*;

02

03const COLUMNS:uint=10;

04const ROWS:uint=10;

05

06var imagesGrid : Array = new Array();

07

08var imageLoader:Loader = new Loader();

09imageLoader.load(new URLRequest("myImage.jpg"));

10imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);

11

12function onImageLoaded(e:Event):void {

13

14 var originalBitmapData:BitmapData = e.target.content.bitmapData;

15

16 var imageWidth : Number = originalBitmapData.width / COLUMNS;

17 var imageHeight : Number = originalBitmapData.height / ROWS;

18

19 for (var i = 0; i < COLUMNS; i++) {

20

21 for (var j = 0; j < ROWS; j++) {

22

23 var imageHolder:MovieClip = new MovieClip();

24

25 var image:Bitmap = new Bitmap();

26 image.bitmapData=new BitmapData(imageWidth,imageHeight);

27 image.bitmapData.copyPixels(

28 originalBitmapData,

29 new Rectangle(i * imageWidth, j * imageHeight,imageWidth, imageHeight),

30 new Point(1,1));

31

32 imageHolder.addChild(image);

33

34 imageHolder.x=i*imageWidth;

35 imageHolder.y=j*imageHeight;

36 imageHolder.alpha=0;

37

38 imagesGrid.push(imageHolder);

39 addChild(imageHolder);

40 }

41 }

42

43 revealImage();

44}

45

46function revealImage():void{

47 for (var i:int = 0; i < imagesGrid.length; i++){

48 var imageGrid:MovieClip = imagesGrid[i] as MovieClip;

49 TweenLite.to(imageGrid, .3, { alpha: 1,delay:i*.15});

50 }

51}
]

http://eng.inbforum.com

上一页INBforum   Go down

上一页INBforumView previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum

Copyright ©2009-2016 LTD Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

IT:SINGLESERVGoogle谷歌翻译TranslateFORUMSOFTLAYERGoogle谷歌广告联盟AdSenseAsia

 

Free forum | ©phpBB | Free forum support | Report an abuse | Forumotion.com