Flash/flex learning notes (21): Using colortransform to change the color and transparency of Objects

Source: Internet
Author: User

Transform is one of the attributes of flash. display. displayobject, while colortransform is a transform attribute, which means that almost all objects can use the colortransform attribute.

 

This is an official explanation:

When a colortransform object is applied to a display object, a new value is calculated for each color channel as follows:

New Red value = (old red value * redmultiplier) + redoffset
New Green value = (old green value * greenmultiplier) + greenoffset
New blue value = (old blue value * bluemultiplier) + blueoffset
New Alpha value = (old Alpha value * alphamultiplier) + alphaoffset (Note: I tested it, as if this line of formula is useless)
If the calculated value of any color channel is greater than 255, the value is set to 255. If the value is smaller than 0, it is set to 0.

 

This can be used to change the R, G, and B color components and transparency of almost any object. To put it bluntly, you can change the red car to a green car or change the black face to a white face. The following is an example.Code:

Txtredmultiplier. addeventlistener (event. change, changehandler); txtgreenmultiplier. addeventlistener (event. change, changehandler); txtbluemultiplier. addeventlistener (event. change, changehandler); txtalphamultiplier. addeventlistener (event. change, changehandler); txtredoffset. addeventlistener (event. change, changehandler); txtgreenoffset. addeventlistener (event. change, changehandler); txtbluemultiplier. addeventlistener (event. change, changehandler); txtalphamultiplier. addeventlistener (event. change, changehandler); function changehandler (E: Event) {var redmultiplier: Number = txtredmultiplier. value; var greenmultiplier: Number = txtgreenmultiplier. value; var bluemultiplier: Number = txtbluemultiplier. value; var alphamultiplier: Number = txtalphamultiplier. value; var redoffset: Number = txtredoffset. value; var greenoffset: Number = txtgreenoffset. value; var blueoffset: Number = txtblueoffset. value; var alphaoffset: Number = txtalphaoffset. value; // trace ("redmultiplier =" + redmultiplier); // trace ("greenmultiplier =" + greenmultiplier); // trace ("bluemultiplier =" + bluemultiplier ); // trace ("alphamultiplier =" + alphamultiplier); var color: colortransform = new colortransform (gradient, greenmultiplier, delimiter, alphamultiplier, redoffset, greenoffset, blueoffset, alphaoffset); R. transform. colortransform = G. transform. colortransform = B. transform. colortransform = RGB. transform. colortransform = IMG. transform. colortransform = color;} changehandler (null); stop ();

It can also be seen from this example that if you want to remove the red weight in the color of an image, you only need to set the redmultiplier to 0. However, after the red weight is eliminated, the value becomes 0, that is, the original red part will turn black. If you want to change pure red to pure green, you need to set greenoffset to 255.

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.