一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

flash as3.0 改变影片剪辑的颜色方法总结

时间:2022-06-28 22:15:07 编辑:袖梨 来源:一聚教程网

AS3.0 动态改变影片剪辑的颜色

 代码如下 复制代码

var a:ColorTransform = new ColorTransform();
a.color = 0x000000;
mc.transform.colorTransform = a;
stage.addChild(mc);

改变mc的颜色

ColorTransform () 构造函数

 代码如下 复制代码

public function ColorTransform(redMultiplier:Number = 1.0, greenMultiplier:Number = 1.0, blueMultiplier:Number = 1.0, alphaMultiplier:Number = 1.0, redOffset:Number = 0, greenOffset:Number = 0, blueOffset:Number = 0, alphaOffset:Number = 0)

方法二:
 

 代码如下 复制代码
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;

 代码如下 复制代码

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);
        }
    }
}

热门栏目