Flash8 tips: Use Bitmapdata.floodfill to do the color filling game

Source: Internet
Author: User

The fill game before Flash8 is usually to separate the colored objects into several small movieclip, and then fill the color separately.

Using Bitmapdata.floodfill to fill the color of the bitmap objects to achieve the region fill color, it seems more convenient, as long as the line to import into the flash, into the bitmapdata can fill color. Here is an example

Effect Demo

Click here to download the source file

Import Flash.display.BitmapData;

var colornumber:number=15; Number of color blocks
var Nowcolor:number; Record current color
var shownowcolor:color=new Color (This.attachmovie ("block", "SHOWNOWCOLORMC", 100,{_x:460,_y:330,_width:50,_height : 50})); Generate a color block to display the current color

for (Var i:number=0;i<colornumber;i++) {//Generate control color block
This.attachmovie ("Block", "Block" +i,i+10,{_x: (i*30+10), _y:350});
var tmpmc:movieclip=eval ("block" +i);
var tmpcolormc:color=new Color (TMPMC);
var tmpcolor:number=random (0XFFFFFF); Random Color
Tmpcolormc.setrgb (Tmpcolor);
Shownowcolor.setrgb (Tmpcolor);
Tmpmc.onrelease=function () {
Shownowcolor.setrgb (Nowcolor);

var mybitmapdata:bitmapdata = Bitmapdata.loadbitmap ("Fillpic"); Create a Bitmap object
var mc:movieclip = This.createemptymovieclip ("MC", 1);
Mc.attachbitmap (mybitmapdata,2); Load Bitmap objects

Mc.onrelease=function () {//click to set Color
Mybitmapdata.floodfill (This._xmouse,this._ymouse, Nowcolor); Fill color for current position (contiguous area of the same color, here is white)
FloodFill performs a dumping fill on the image, starting with the (x, y) coordinates to fill a particular color.

By extending the instance, you can make the following effect

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.