Practice experience of Flash8 pixel dissolution function

Source: Internet
Author: User
Experience tonight practice the Pixeldissolve method of BitmapData class, this method can realize pixel dissolve function of image. I do the effect here:

Click here to download the source file

If you don't see it, you can also click on the link at the bottom to have the source file.

The first time in the online flash to complete this effect, I could not believe that flash can do so, remember the first time when learning Flash, ancient brother did a similar effect, is really good trouble, now step by step to learn the new characteristics of Flash8, found that everything changed so simple

Don't say much, start.

This effect uses the BitmapData class Pixeldissolve method, because is the picture dissolves, therefore also uses the BitmapData class the LoadBitmap method.

Idea is: 1: First use LoadBitmap load library with the link identifier of the picture, note the LoadBitmap method, the code must write this: Mybitmapdata:bitmapdata = Bitmapdata.loadbitmap (LinkId : Sting); and create a copy so that the image can be recycled.

2: Create a custom function that defines how the Pixeldissolve is dissolved, followed by a code explanation.

3: The specific way to write their own dissolution, the following is my code to write, there are detailed explanations, I hope you can read

4: There is a small trick to set the total pixel value of the picture, so that you can stop the cycle in time to reduce the burden on the CPU, and the image of the pixel value is actually equal to the length of the picture multiplied by the width .

Code requirements: There are two or more pictures in the library, all with identifiers. The picture is the best size. The code looks very long, but it's all basic and simple.

File://by Guan
Import flash.display.*;
Import flash.geom.*;
file://set odd, even-numbered judgments, used in the back, mainly used to loop the picture demo.
var Bofang:boolean = true;
file://set three BitmapData objects, where bit1, Bit2 is a bitmap in the call library, Bit3 is a copy of bit1, bit1 changes do not affect bit3;
var bit1:bitmapdata = Bitmapdata.loadbitmap ("Id1");
var bit2:bitmapdata = Bitmapdata.loadbitmap ("Id2");
var bit3:bitmapdata = Bit1.clone ();
FILE://creates an MC to make the bit1 image appear.
var mc1:movieclip = This.createemptymovieclip ("MC", This.getnexthighestdepth ());
Mc1.attachbitmap (Bit1, this.getnexthighestdepth ());
The file://custom function, in fact, is the pixel dissolution function of the bitmapdata.
File://function melts (pixel-dissolved random seeds, dissolved objects, target sources, initial dissolved pixels, maximum dissolved pixels) {}
function Ronghua (Randomnum:number, Duixiang:bitmapdata, Mubiao:bitmapdata, Minnum:number, Maxnum:number) {
Duixiang.pixeldissolve (Mubiao, Mubiao.rectangle, New Point (0, 0), Randomnum, minnum);
if (minnum>maxnum) {
file://Deletes a frame call when the number of underlying dissolved pixels is greater than the overall pixel of an image.
File://trace ("OK");
Delete This.onenterframe;
}
}
file://the function of the image when the button is pressed
mc1.onpress = function () {
The dissolution value of FILE://Foundation is 400;
var minnum:number = 400;
The maximum pixel value of the file://image is equal to its height multiplied by the width.
var maxnum:number = this._height*this._width;
file://set the seed value of random dissolution to 9 digits.
var randomnum:number = Math.floor (Math.random () *10);
file://if it is the first time press the button, Bofang=true;
if (Bofang) {
FILE://-Frame call, the base dissolved value increasing, call the custom function, the image is dissolved into a second image, dissolved, automatically stop
Onenterframe = function () {
Minnum + 200;
Ronghua (Randomnum, Bit1, Bit2, Minnum, maxnum);
};//began to allow a second dissolution, bofang=false;
Bofang =!bofang;
else {//base dissolved pixels back to 0,
Minnum = 0;
Onenterframe = function () {//IBID., when dissolved here, a copy of the bit1 is used bit3.
Minnum + 200;
Ronghua (Randomnum, Bit1, Bit3, Minnum, maxnum);
};
Bofang =!bofang;
}
};

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.