[As Functional Code Tutorial 12] Fill games

Source: Internet
Author: User

In this course we will learn to use the color class to create a color-filled game

and review the application of for...in and sharedobject through this example

Ideas:

1. Use scripting code to create a palette, click on the color block after the mouse to take color;

2. Draw the movie clip as a fill and save each part as a movie clip. For example: The Padding object is a character, so to put his hair, eyes, face and other parts are saved into a movie clip;

3. Finally, each part of the film is again saved to a film clip (MC);

4. In order to save and read the colors in the video in the MC, add two buttons save_btn and load_btn.

Step 1:

Draws a movie clip as a fill and saves each part as a movie clip;

Finally, each part of the film is saved to a movie clip, the instance name MC;

Draw two button instance names save_btn and load_btn respectively.

Step 2:

Add as Code

===== draw a square as a color block to invoke =====
_root.createemptymovieclip ("box",-1);
var box_size:number = 12;
var thecol = 0x0;
Used to store the color values that are taken
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;
//============================================
A palette is generated below *************
var panex:number = 3;
var paney:number = 3;
var column:number = 18;
The starting X coordinate is 3, the start Y coordinate is 3, and the Total row number 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 << | g << 8 | b);
RGB conversion formula, both of these can be used
p._x = Panex + Math.floor (i/column) * (box_size+1);
p._y = Paney + i%column* (box_size+1);
Sets the coordinate row coordinates for each color block: [i/column], column coordinates: i%column
P.onrelease = function () {
Thecol = new Color (this). getRGB ();
New Color (curser.bg). Setrgb (Thecol);
Click on the color swatch to take the color and save it to the Thecol variable
};
i++;
}
}
}
//******************************************
===== to decide which movie clip to fill after clicking on the pattern =====
Mc.onrelease = function () {
var Flag:boolean = true;
Add a flag to avoid filling multiple movies at once
For (var k in MC) {
if (Mc[k].hittest (_xmouse, _ymouse, True) && flag) {
New Color (Mc[k]). SETRGB (Thecol);
Flag = false;
}
}
};
//============================================
Read and save ************* for all fill colors in the MC
Save_btn.onrelease = function () {
var so:sharedobject = sharedobject.getlocal ("Color_save");
For (var k in MC) {
SO.DATA[K] = new Color (Mc[k]). getRGB ();
}
};
Load_btn.onrelease = function () {
var so:sharedobject = sharedobject.getlocal ("Color_save");
For (var k in MC) {
New Color (Mc[k]). SETRGB (So.data[k]);
}
};
//******************************************

Flash Charging: A brief introduction of common methods in color class

Note that the use of GETRGB () does not get the RGB value of a movie clip that we draw on the stage even if it is filled with a solid color movie. We can only use the SetColor () to get the color value of the movie with getRGB ().

Example 1: Create a Color object named M_col for the movie clip MC and set its RGB value to orange:

var my_color:Color = new Color(my_mc);
my_color.setRGB(0xff9933);

Example 2: Gets the RGB value of the movie clip Mc and displays it in 16:

var m_Col:Color = new Color(mc);
m_Col.setRGB(0xff9933);
var myValue:String = m_Col.getRGB().toString(16);

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.