Flash as3.0 A summary of color methods for changing movie clips

Source: Internet
Author: User
Tags addchild

AS3.0 dynamically change the color of a movie clip

The code is as follows Copy Code

var a:colortransform = new ColorTransform ();
A.color = 0x000000;
Mc.transform.colorTransform = A;
Stage.addchild (MC);

Change the color of the MC

ColorTransform () constructor

The code is as follows Copy Code

Public Function ColorTransform (Redmultiplier:number = 1.0, Greenmultiplier:number = 1.0, Bluemultiplier:number = 1.0, ALP Hamultiplier:number = 1.0, Redoffset:number = 0, Greenoffset:number = 0, Blueoffset:number = 0, Alphaoffset:number = 0)

Method Two:

The code is as follows Copy Code
var color:colortransform=new colortransform ();
color.redmultiplier=0;
color.greenmultiplier=0;
color.bluemultiplier=0;
color.alphamultiplier=0;
color.redoffset=255;
color.greenoffset=0;
color.blueoffset=255;
color.alphaoffset=255;
Mc.transform.colortransform=color;

Cases

The code is as follows Copy Code

Package {
Import Flash.display.Sprite;
Import Flash.display.GradientType;
Import Flash.geom.ColorTransform;
Import flash.events.MouseEvent;

public class Colortransformexample extends Sprite {
Public Function Colortransformexample () {
var target:sprite = new Sprite ();
Draw (target);
AddChild (target);
Target.usehandcursor = true;
Target.buttonmode = true;
Target.addeventlistener (Mouseevent.click, ClickHandler)
}
Public function Draw (Sprite:sprite): void {
var red:uint = 0xff0000;
var green:uint = 0x00ff00;
var blue:uint = 0x0000ff;
var size:number = 100;
Sprite.graphics.beginGradientFill (Gradienttype.linear, [Red, blue, green], [1, 0.5, 1], [0, 200, 255]);
Sprite.graphics.drawRect (0, 0, 100, 100);
}
Public Function ClickHandler (event:mouseevent): void {
var roffset:number = Transform.colorTransform.redOffset + 25;
var boffset:number = transform.colortransform.redoffset-25;
This.transform.colorTransform = new ColorTransform (1, 1, 1, 1, roffset, 0, Boffset, 0);
}
}
}

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.