The fourth chapter of Flash Basic theory class rendering technology Ⅰ

Source: Internet
Author: User

Back to "flash Basic Theory Class-Catalog"

In the drawing example seen in the previous chapter, only a few very simple drawing instructions were used, and we mentioned the mysterious "drawing API" several times before, but they were not explained in detail. In this chapter we'll learn to use ActionScript to create visual elements, including ActionScript colors, drawing APIs, ColorTransform classes, Filters (filter), and BitmapData (bitmap) classes. Color is used in many parts of this chapter, so let's learn the first lesson.

Colors in Flash

In Flash, color is a series of special numbers, one color value can be 0 to 16,777,215 of any number, which is 24 bit color. You may be asked why there are 16,777,216 (256 * 256 * 256) color values because Flash uses RGB color values, meaning that each color can be made up of red, green, and Blue (blue) three colors. Each of these three synthetic colors is a number from 0 to 255, so there are 256 possible depths for each red and yellow blue, with about 16.78 million colors.

The system is called 24-bit color because it uses 8 bits (0 or 1) to represent 256 values. 8-bit times 3 (red, yellow, blue) means that 24 bits are required to represent 16.78 million color values. We'll also learn about the 32-bit color system, which has an extra 8-bit value for transparency (alpha).

It's hard to imagine what a 11,273,634-value color is. As a result, developers typically use a different numeric representation system: hexadecimal. If you have used color in HTML, then this is not unfamiliar to you, but anyway, let's learn the basics.

Use hexadecimal to represent color values

hexadecimal (hexadecimal, abbreviated HEX), based on 16, each digit is any number 0 to 15, and the decimal is based on 10, each digit is 0 to 9 of any number. Since there are no numbers that can represent 10 to 15, use the first six letters of the alphabet, a through F, to represent them. In this way, each 16 number can be one of 0 to F (in Flash, the hexadecimal number is case-insensitive, using a to f or a to f). Use the number 16 in HTML to be labeled with # as a prefix. As in other languages, in ActionScript, 0x is used as a prefix. For example, hexadecimal 0xA is equal to decimal 10, and 0xF equals 15,0x10 equals 16. In decimal, each digit is 10 times times the number on its right, as 243 is 100 times times 2, 4 is 10 times, 3 is 1 time. In hexadecimal, each digit is 16 times times the number on its right, such as 0x2b3 256 times times 2, B (or 11), 16 times times 3.

For 24-bit, it's equal to 0xFFFFFF, and the 6 hexadecimal numbers can be divided into three parts. The first part is red, the second part is green, and the last two are blue, which is symbolically recorded as 0xRRGGBB.

Remember that each synthetic color can be a value from 0 to 255 (hexadecimal indicates: 0x00 to 0xFF). Therefore, red can be expressed as 0xff0000, which indicates pure red, because its green is 0, blue is 0. Similarly, 0x0000ff represents pure blue.

Take 11,273,634 as an example, convert it to 16 (a simple method later), the result is 0xac05a2, you can break it down to red (red) = Ac,green (green) = 05,blue (blue) = A2. You can see that red (red) and blue (blue) are relatively high, and green is almost no, and we can guess that the color is probably purple, which is not visible in the decimal number. Note that in ActionScript, you can use a binary representation in a function that uses a color value to use both decimal and hexadecimal. For Flash, 11,273,634 and 0XAC05A2 are a number, but for poor humans the latter notation is easier to read.

So how to convert between two systems, it's very easy to convert 16 to decimal. As long as you output this hexadecimal number, the trace function automatically converts it to decimal.

trace(0xAC05A2);

converting decimal to hexadecimal uses the toString (16) function, such as:

trace((11273634).toString(16));

The output is AC05A2, and if you want to use this number, don't forget to add 0x.

Transparency and 32-bit color

Previously mentioned, in addition to 24-bit color, there are 32-bit color, more than 8 bits to represent transparency. Just like the angle system (chapter three), as 3 is somewhat promiscuous in the use of 24 and 32-bit colors. The drawing API as 3 is largely based on Flash MX (Flash 6), and in short, the drawing API function uses a special parameter to specify transparency, so it also takes 24-bit colors. In addition, the BitmapData class is added from Flash 8 and uses 32-bit color. If you have questions about which color system a function uses, check your ActionScript reference manual.

We can use hexadecimal to represent a color value in a format such as 0xRRGGBB. Similarly, the 32-bit color is the same, expressed in a format such as 0xAARRGGBB, where AA represents transparency. As a result, 0xFFFFFFFF means opaque white, 0x00ffffff represents completely transparent white, and 0X80FFFFFF represents approximately 50% transparent white.

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.