ColorTransform 应用举例。

      Flash课件设计 2006-6-8 21:48
flash8 中已经不推荐使用 Color 类了,取而代之的是 ColorTransform,从字面上看,flash 对类的划分越来越趋于标准化,类的使用也越来越普遍,因此,让我们跑步前进,加快类的学习。
  flash8 中关于ColorTransform 有这样一段示例代码:

import flash.geom.ColorTransform;
import flash.geom.Transform;
//导入相关的类定义文件

var colorTrans:ColorTransform = new ColorTransform();
trace(colorTrans.greenOffset); // 0
//定义一个 ColorTransform 对象实例,用于承载 目的色。


var rect:MovieClip = createRectangle(220, 280, 0x000000);
var trans:Transform = new Transform(rect);
//定义一个 Transform 对象,实现对指定 MC 的引用。

onEnterFrame = function(){
  colorTrans.greenOffset += 5;
  trace(colorTrans.greenOffset); // 255
  trans.colorTransform = colorTrans;
     //对 Transform 对象中的 colorTransform 对象进行赋值。
  if ( colorTrans.greenOffset >= 255){
    //delete this.onEnterFrame;
    colorTrans.greenOffset = 0;
  }
}

function createRectangle(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
scope = (scope == undefined) ? this : scope;
var depth:Number = scope.getNextHighestDepth();
var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
mc.beginFill(color);
  mc.moveTo( 100,100);
mc.lineTo(100, height);
mc.lineTo(width, height);
mc.lineTo(width, 100);
mc.lineTo(100, 100);
return mc;
}

  由上面的代码可以看出,Transform 对象中包含了一个内部的 ColorTransform 对象,并且只能通过外部的ColorTransform 对象对其进行整体的赋值,单独的指定 trans.colorTransform.rgb = 0xffffff 是没有意义的。
  对于独立的ColorTransform 对象来说,既可以对某一种颜色进行指定,也可以按照十六进制数值进行指定,控制程度得到了加强。
  根据这个例子进行改写得到下面的一个应用:


Flash 动画
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}