【发布时间】:2015-06-26 07:05:30
【问题描述】:
尽管在网络和 youtube 上都搜索了解决方案,但仍然很难找到有关在 AS3 中对多个影片剪辑进行颜色转换的信息。我在 youtube 上找到了一个关于 colorTransform 的视频,我按照步骤为单个剪辑创建了一个功能齐全的 colorTransform,但我想将它用于多个剪辑,并且能够通过鼠标单击更改每个剪辑的颜色。
我已经包含了下面的代码,也许有人知道我可以如何添加更多的电影剪辑。当我复制和更改 mc1.到 mc2 的 EventListener 代码,我得到一个重复的函数错误,我不知道如何修复。
import flash.geom.ColorTransform;
import flash.geom.ColorTransform;
import flash.events.MouseEvent;
// this here is the little movieclip where the main clip gets its color from,the clip is made up of two movieclips but can also be one movieclip
// instead of brushColor i have used myColor and instead of brush.tip i have used square.
var myColor:ColorTransform=new ColorTransform();
myColor.color=0xffffff; square.transform.colorTransform=myColor
red.addEventListener(MouseEvent.CLICK,onclick);
green.addEventListener(MouseEvent.CLICK,onclick);
blue.addEventListener(MouseEvent.CLICK,onclick);
orange.addEventListener(MouseEvent.CLICK,onclick);
yellow.addEventListener(MouseEvent.CLICK,onclick);
pink.addEventListener(MouseEvent.CLICK,onclick);
function onclick(event:MouseEvent){
if(event.target==red)
{myColor.color=0xff0000}
else if(event.target==green)
{myColor.color=0x99ff33}
else if(event.target==blue)
{myColor.color=0x00ccff}
else if(event.target==orange)
{myColor.color=0xffcc33}
enter code here
else if(event.target==yellow)
{myColor.color=0xffff66}
else if(event.target==pink)
{myColor.color=0xff99ff}
else
{myColor.color=0x666666}
square.transform.colorTransform=myColor
}
mc1.addEventListener(MouseEvent.CLICK, colorChange);
function colorChange(event:MouseEvent)
{
mc1.transform.colorTransform=myColor;
}
// upto here the code works fine but from below i get a duplicate fuction error which i don't know how to fix.
// the idea is to add more movie clips so i can change their colors just like i can do for mc1.
1021: DUPLICATE FUNCTION DEFINITION "ERROR"
mc2.addEventListener(MouseEvent.CLICK, colorChange);
function colorChange(event:MouseEvent)
{
mc2.transform.colorTransform=myColor;
}
【问题讨论】: