我试图改变一个电影的颜色,当点击,但我有一个阴影过滤器,我想保持黑色。
var cty:ColorTransform = new ColorTransform();
cty.color = 0xFFFF00; //color transform yellow
var shdw:DropShadowFilter = new DropShadowFilter();
shdw.color = 0x000000; <----clearly set to black
shdw.distance = 3;
shdw.angle = 45;
shdw.strength = 1;
shdw.blurX = 3;
shdw.blurY = 3;
thisclip.filters=[shdw];
thisclip.addEventListener(MouseEvent.CLICK,myevent);
function myevent(e:MouseEvent):void
{
thisclip.transform.colorTransform = cty;
thisclip.filters=[shdw]; <------ tried adding a refresher but doesnt work
}问题是,在改变颜色后,阴影被改变为与物体相同的颜色,有什么方法可以在不改变阴影滤镜颜色的情况下改变颜色?
发布于 2016-05-01 15:03:20
问题是,在改变颜色后,阴影被改变为与物体相同的颜色,有什么方法可以在不改变阴影滤镜颜色的情况下改变颜色?
你需要分开你想要被投阴影的项目和你想要颜色转换的项目。一种方法是为thisclip创建一个“容器”,并将阴影应用到容器本身,然后只转换this clip的颜色。我修改了你的代码以表明我的意思..。
var cty:ColorTransform = new ColorTransform();
cty.color = 0xFFFF00; //# yellow
var shdw:DropShadowFilter = new DropShadowFilter();
shdw.color = 0x000000; //# black
shdw.strength = 1;
shdw.distance = 3; shdw.angle = 45;
shdw.blurX = shdw.blurY = 3; //# linked since same value for both
var contMC : MovieClip = new MovieClip;
addChild( contMC ); //# add to stage
contMC.addChild( thisclip ); //# add "thisclip" into container MC
contMC.x = 0; contMC.y = 0; //# set your own position
//thisclip.filters=[shdw];
contMC.filters=[shdw];
thisclip.addEventListener(MouseEvent.CLICK, myevent);
function myevent(e:MouseEvent):void
{
thisclip.transform.colorTransform = cty;
//e.currentTarget.transform.colorTransform = cty; //# use this for ANY listening object
}请记住,如果您通过代码创建容器MC (如我所展示的),您可以引用任何添加的子实例名,其通常名称如下:thisclip.transform.colorTransform = cty;
但是,如果在舞台上创建容器MC (实例名为contMC,并将thisclip MC剪切/粘贴到其中),那么现在可以将其代码引用为:contMC.thisclip.transform.colorTransform = cty;。
提示#1 :为了避免添加容器,如果您的thisclip本身有一个MC (或雪碧)包含一些“要着色”的内容,您可以使用它的实例名来针对该内容:
thisclip.someContent.transform.colorTransform = cty;
(在这里,thisclip变成了带有阴影的容器,而someContent是要进行颜色转换的内部MC )。
提示2 :,我添加了行e.currentTarget.transform.colorTransform = cty; (但由于没有使用而被注释掉),以显示如何让点击的MC响应颜色转换。只要确保他们听的是这样的事件:
clipInstanceName.addEventListener(MouseEvent.CLICK, myevent);
(现在您可以拥有多个,如果在if语句中使用cty.color = some new Value;检查并相应地调整每个单击项的颜色,则在最后设置.colorTransform = cty; .
https://stackoverflow.com/questions/36964670
复制相似问题