Flex 修改shape颜色的方法

 flash打包资源成swc组件,在flex中引用

修改shape颜色的方法如下:

         var child:Shape = mc.getChildAt(jj) as Shape;
         
         var newTranColor:ColorTransform = child.transform.colorTransform;
         //var newMatrix:Matrix = child.transform.matrix;
         newTranColor.color = 0x00ff00;
         child.transform.colorTransform = newTranColor;


相关说明如下:

一个对象,具有与显示对象的矩阵、颜色转换和像素范围有关的属性。在 Transform 类的条目中对特定属性 matrix、colorTransform 和三个只读属性( concatenatedMatrixconcatenatedColorTransformpixelBounds)进行了说明。

transform 对象的每个属性本身都是一个对象。此概念很重要,因为设置 matrix 或 colorTransform 对象的新值的唯一方法是,创建新对象并将该对象复制到 transform.matrix 或 transform.colorTransform 属性。

例如,要增加显示对象矩阵的 tx 值,您必须制作整个矩阵对象的副本,然后将新对象复制到 transform 对象的 matrix 属性中:


    var myMatrix:Matrix = myDisplayObject.transform.matrix;  
    myMatrix.tx += 10; 
    myDisplayObject.transform.matrix = myMatrix;  
    

不能直接设置 tx 属性。下面的代码对 myDisplayObject 不起作用:


    myDisplayObject.transform.matrix.tx += 10;
    

您也可以复制整个 transform 对象并为其赋予另一个显示对象的 transform 属性。例如,下面的代码将整个 transform 对象从 myOldDisplayObj 复制到 myNewDisplayObj

myNewDisplayObj.transform = myOldDisplayObj.transform;

现在,新显示对象 myNewDisplayObj 与旧显示对象 myOldDisplayObj 具有相同的矩阵、颜色转换和像素范围值。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值