[As feature code tutorial 09] Dot Matrix effect

Source: Internet
Author: User
Tags remove filter

The first time I saw this on Fanflash, it was incredible.

A closer look at the findings, the author's idea is still very ingenious, today to share with you

This example can be said to combine the BitmapData class of technology and tween class of dynamic.

Ideas:

1. Use as to create an empty text box to store the words you want to display;

2. Think of this text box as a bitmap and store its bitmap data;

3. Scan the bitmap data by line and store the pixel points with text information in the array;

4. Finally, the "point" is copied from the array and each "point" is moved to the appropriate location.

Step 1:

Draw 10*10 Dots, save as movie clips, connect-> Export-> Identifier "dot"

Step 2:

Add as code:

Import Flash.display.BitmapData;
Import Mx.transitions.Tween;
Import mx.transitions.easing.*;
Import BitmapData and Tween classes
_root.createtextfield ("TXT",-1,-100,-100, 0, 0);
Txt.autosize = true;
Txt.text = "Enter the text to display";
Create an empty text box to store the input text
var bm:bitmapdata = new BitmapData (Txt._width,txt._height, False, 0XFFFFFF);
Bm.draw (TXT);
The TXT as a bitmap, and TXT bitmap information into MB
var dotarray:array = new Array ();
Request an array to store MB bitmap information
var w:number = 4;
var h:number = 4;
W,h width and height, respectively.
for (y=0 y < txt._height; y++) {

for (x=0 x < txt._width/x + +) {

if (Bm.getpixel (x, y)!= 0xffffff) {
Dotarray.push ({x:x*w, y:y*h});
column by row Pixel, put the pixel position of the word into the array and multiply the w,h to extend the distance
}
}
}
_root.createemptymovieclip ("MC",-1);
mc._x = 10;
Mc._y = 150;
============ copy "Dot" =============== based on Array
for (var i = 0; i < dotarray.length; i++) {

var p = mc.attachmovie ("dot", "dot" +i, i);

P.cacheasbitmap = true;

Bitmap caching of "dots"
p._x = Math.random () *stage.width;
P._y = Math.random () *stage.height;
Give each "dot" a random starting point
P.tox = dotarray[i].x;
P.toy = DOTARRAY[I].Y;
Tox,toy is the end of each point to move to

var speed = Math.random () *4;

New Tween (P, "_x", Back.easeout, p._x, P.tox, speed, true);
New Tween (P, "_y", Back.easeout, P._y, P.toy, speed, true);
Using the Tween class, let each "point" move to their endpoint coordinates
}

Flash Charge: Movieclip.cacheasbitmap Properties

1. Function: If set to True, Flash Player caches the internal bitmap representation of the movie clip. This can improve the performance of movie clips that contain complex vector content.

2. Principle: The vector figure is small, but the comparison consumes computational resources; bitmaps compare memory resources, but they consume less computational resources.

3. Simply put: Cacheasbitmap is to convert vector map to bitmap, save CPU, but consume memory, can increase the operation speed of vector graph.

4. Note: Cacheasbitmap is most suitable for the MC that contains a large amount of static content and does not require frequent scale and rotation.

5. Default: When you add filter (filter) to the MC, Cacheasbitmap automatically set to True, even if you forcibly let cacheasbitmap=false also change. Only when you remove Filter,cacheasbitmap will return the most recently set logical value.

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.