Flash color filling game

Source: Internet
Author: User
9. [AS function code tutorial 12] color filling game
In this course, we will learn how to use the Color class to create a Color filling game.
In this example, we will review the applications of for... in and mongodobject.

Ideas:
1. Use the script code to create a color palette. Click the color block to retrieve the color;
2. Draw a filled video clip and save each clip as a video clip. For example, if the filling object is a character, you need to save his hair, eyes, face, and other parts as video clips;
3. Finally, save each part of the video to a single video clip (mc;
4. To save and read the color of each clip in mc, add two buttons save_btn and load_btn.



Step 1:
Draw a filled video clip and save each part as a video clip;
Finally, save each part of the video to a single video clip with the instance name mc;
The two button instances are named save_btn and load_btn respectively.
Step 2:
Add AS code
// ==== Draw a square as a color block for future calls ====
_ Root. createEmptyMovieClip ("box",-1 );
Var box_size: Number = 12;
Var TheCol = 0x0;
// Stores the obtained color values.
With (box ){
BeginFill (TheCol );
MoveTo (0, 0 );
LineTo (box_size, 0 );
LineTo (box_size, box_size );
LineTo (0, box_size );
LineTo (0, 0 );
EndFill ();
}
Box. _ visible = false;
// ================================================ ======
// ************* Generate a color palette *************
Var panex: Number = 3;
Var paney: Number = 3;
Var column: Number = 18;
// The start point x coordinate is 3, the start point y coordinate is 3, and the total number of rows is 18
Var I = 0;
For (var r = 0; r <= 0xFF; r + = 0x33 ){
For (var g = 0; g <= 0xFF; g + = 0x33 ){
For (var B = 0; B <= 0xFF; B + = 0x33 ){
Var p: MovieClip = box. duplicateMovieClip ("box" + I, I );
New Color (p). setRGB (r * 256*256 + g * 256 + B );
// New Color (p). setRGB (r <16 | g <8 | B );
// RGB conversion formula, which can be used
P. _ x = panex + Math. floor (I/column) * (box_size + 1 );
P. _ y = paney + I % column * (box_size + 1 );
// Set the coordinate line coordinates of each color block: [I/column], and the column coordinates: I % column
P. onRelease = function (){
TheCol = new Color (this). getRGB ();
New Color (curser. BG). setRGB (TheCol );
// Click the color block to save the color to the TheCol variable.
};
I ++;
  }
}
}
//************************************** ****
// =======Determine which video clip to fill after clicking on the image ======
Mc. onRelease = function (){
Var flag: Boolean = true;
// Add a flag to avoid coloring multiple videos at a time.
For (var k in mc ){
If (mc [k]. hitTest (_ xmouse, _ ymouse, true) & flag ){
New Color (mc [k]). setRGB (TheCol );
Flag = false;
  }
}
};
// ================================================ ======
// ************* Read and save all fill colors in mc *************
Save_btn.onRelease = function (){
Var so: export dobject = export dobject. getLocal ("Color_save ");
For (var k in mc ){
So. data [k] = new Color (mc [k]). getRGB ();
}
};
Load_btn.onRelease = function (){
Var so: export dobject = export dobject. getLocal ("Color_save ");
For (var k in mc ){
New Color (mc [k]). setRGB (so. data [k]);
}
};
//************************************** ****



Flash Charging: common methods in Color
Note: Even if the video clip we draw on the stage is filled with a solid color film, it will not get its RGB value using getRGB. We can use getRGB () to obtain the color value of the video only after setColor () is used.



Example 1: create a Color object named m_Col for the video clip mc and set its RGB value to Orange:
Var my_color: Color = new Color (my_mc );
My_color.setRGB (0xff9933 );



Example 2: obtain the RGB value of the video clip mc and display it in hexadecimal format:
Var m_Col: Color = new Color (mc );
M_Col.setRGB (0xff9933 );
Var myValue: String = m_Col.getRGB (). toString (16 );


This is the end of the tutorial.
QQ: 147461195 (FL Foundation master)

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.