简体   繁体   English

actionscript-3中的乘法条件不起作用

[英]multiply condition in actionscript-3 does not work

When i try to make a multiply condition. 当我尝试做一个乘法条件时。 it's always error. 总是错误。 can you tell me where my fault? 你能告诉我我的错在哪里吗? Thanks 谢谢

var score:Number = 0;

addEventListener(Event.ENTER_FRAME, totalScore);

function totalScore(e:Event){
    if(
        to_konten1_1.visible = false &&
        to_konten1_2.visible = false &&
        to_konten1_3.visible = false &&
        to_konten1_4.visible = false &&
        to_konten1_5.visible = false &&
        score > 20){
            gotoAndStop(2);
    } else if(
        to_konten1_1.visible = false &&
        to_konten1_2.visible = false &&
        to_konten1_3.visible = false &&
        to_konten1_4.visible = false &&
        to_konten1_5.visible = false &&
        score < 20){
            gotoAndStop(3);
        }

I think this worth explaining a bit. 我认为这值得解释。 The if (condition) expression needs condition to be Boolean but does not require so. if(条件)表达式需要将条件设为布尔值,但不需要。 Instead, it tries to cast the given expression by the number of rules to get its Boolean value. 相反,它将尝试通过规则数量强制转换给定表达式以获取其布尔值。

Boolean : A => A. 布尔值 :A =>A。

Assignation operator " = ": A=B => B. 赋值运算符“ = ”:A = B =>B。

null , undefined , void : always false . nullundefinedvoid :始终为false

Number , int , uint : 0 => false , Number.NaN => false , otherwise true . Numberintuint :0 => falseNumber.NaN => false ,否则为true

String : "" => false , otherwise true . String :“” => false ,否则为true

Listing : A,B,C => C, although this expression has no particular meaning in AS3 it always returns its last element. 清单 :A,B,C => C,尽管此表达式在AS3中没有特殊含义,但它始终返回其最后一个元素。

Any valid Array , Object , Function , Class or class instance: always true . 任何有效的ArrayObjectFunctionClass或class实例:始终为true

Thus, in your case you could formalize it a bit: 因此,您可以将其正式化:

function totalScore(e:Event):void
{
    if (!anyVisible)
    {
        if (score > 20)
        {
            gotoAndStop(2);
        }
        else if (score < 20)
        {
            gotoAndStop(3);
        }
        else // if score == 20
        {
            // Decide what to do.
        }
    }
}

function get anyVisible():Boolean
{
    var aList:Array = [to_konten1_1, to_konten1_2, to_konten1_3, to_konten1_4, to_konten1_5];

    for each (var DO:DisplayObject in aList)
    {
        if (DO.visible)
        {
            return true;
        }
    }

    return false;
}

错误是您使用单个=进行分配,而不是使用双==进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM