按钮检查动画片段的颜色是否与[AS3]匹配

时间:2015-10-28 09:35:28

标签: actionscript-3 flash

我正在做一个项目,现在它关于着色形状,用户必须选择颜色并点击形状来应用颜色,他们可以点击一个按钮来检查它是否和&# #39;是对的。我设法做所有这些而不是按钮。如何为" check1_btn"编写IF / Else或Switch / Case语句?我要点击的按钮,检查影片剪辑的颜色是否与我选择的颜色相匹配,如果匹配,它将跟踪"好"否则它只会追踪" oops!"

这是选择和删除颜色的代码:

import flash.events.MouseEvent;
import flash.geom.ColorTransform;

var SelColor:Number = 0xEFEFEF;

// Select Color

redpick_mc.addEventListener(MouseEvent.CLICK,RedS);
function RedS (event:MouseEvent):void
{
    SelColor = 0xE14938;
}

orangepick_mc.addEventListener(MouseEvent.CLICK,OrangeS);
function OrangeS (event:MouseEvent):void
{
    SelColor = 0xFBA026;
}

purplepick_mc.addEventListener(MouseEvent.CLICK,PurpleS);
function PurpleS (event:MouseEvent):void
{
    SelColor = 0x553982;
}

greenpick_mc.addEventListener(MouseEvent.CLICK,GreenS);
function GreenS (event:MouseEvent):void
{
    SelColor = 0x61BD6D;
}

bluepick_mc.addEventListener(MouseEvent.CLICK,BlueS);
function BlueS (event:MouseEvent):void
{
    SelColor = 0x2C82C9;
}

yellowpick_mc.addEventListener(MouseEvent.CLICK,YellowS);
function YellowS (event:MouseEvent):void
{
    SelColor = 0xFAC51C;
}

// Fill Color

bigdrop_mc.addEventListener(MouseEvent.CLICK, bdrop);
meddrop_mc.addEventListener(MouseEvent.CLICK, mdrop);
smalldrop_mc.addEventListener(MouseEvent.CLICK, sdrop);

function bdrop(event:MouseEvent):void
{
    var DrawCol = new ColorTransform ();
    DrawCol.color = SelColor;
    bigdrop_mc.transform.colorTransform = DrawCol;
}

function mdrop(event:MouseEvent):void
{
    var DrawCol = new ColorTransform ();
    DrawCol.color = SelColor;
    meddrop_mc.transform.colorTransform = DrawCol;
}

function sdrop(event:MouseEvent):void
{
    var DrawCol = new ColorTransform ();
    DrawCol.color = SelColor;
    smalldrop_mc.transform.colorTransform = DrawCol;
}

这就是我想要做的事情,但是失败了lol:

check1_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void
{
    if  (
        bigdrop_mc.transform.colorTransform.color = 0x61BD6D;

        meddrop_mc.transform.colorTransform.color = 0xFAC51C;

        smalldrop_mc.transform.colorTransform.color = 0xE14938;)
    {

        trace("Good");

    }   
    else 
    {
        trace("Oops..");
    }
}

1 个答案:

答案 0 :(得分:0)

我认为你想要做的是: 替换你的if(...)代码。

 if  (bigdrop_mc.transform.colorTransform.color = 0x61BD6D; meddrop_mc.transform.colorTransform.color = 0xFAC51C; malldrop_mc.transform.colorTransform.color = 0xE14938; )

应该是这样的:

if  (bigdrop_mc.transform.colorTransform.color == 0x61BD6D && meddrop_mc.transform.colorTransform.color == 0xFAC51C &&  malldrop_mc.transform.colorTransform.color == 0xE14938 )

这将做的是检查所有这些颜色,看看它们是否正确。 &&符号是'和'符号,实质上意味着必须满足它之前和之后的语句。使用==比较两个值。