Flash actionscript do picture mosaic effect animation

Source: Internet
Author: User
Tags array array length

  Demo Effect:

Click here to download the source file

1, the production method is very simple, first import a picture of the appropriate size, and then select the picture press F8 to convert it to a movie clip symbol. As shown in figure:




2, then we click to select the picture on the stage, and then press F9 to open the Action panel, add the following code:

onclipevent (load) {///When a movie clip appears on the timeline, executes the statement in the curly brace
Numx =;
Numy = 70;//Defines the dimensions of the image display
Numperframe = 60;//define pin speed
Currsquare = 0;
choices = new Array ();
for (i=0; i<numx*numy; i++) {
Choices.push (i);//define a new array and keep increasing the array length
}
_root.createemptymovieclip (" Mask ", 0);///
This.setmask (_root.mask);//Create a movie clip as a mask
function drawsquare (x, y) {
with (_root.mask) {
MoveTo (x, y);
Beginfill (0x000088);
LineTo (x+10, y);
LineTo (x+10, y+10);
LineTo (x, y+10);
Endfill ()//Draw this mask, the shape is 10*10 pixels
}
}
}
Onclipevent (enterframe) {//Movie clip needle frequency constantly triggers this action
if ( Currsquare<numx*numy) {
for (i=0; i<numperframe; i++) {
J = random (choices.length);
t = choices[j];
Choices[j] = choices[choices.length-1]; Randomly select the time at which the party will appear
Choices.pop ();//start deleting the elements in the array choices
x = t%numx;
y = Math.floor (T/NUMX);//returns the lower value of the expression in the argument
Drawsquare (x*10, y*10);

Currsquare + = Numperframe;
This._alpha = currsquare/(numx*numy) *100;//setting Transparency
}
}

Finally, you can press the Ctrl+enter button to test the film!



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.