如果{var in AS3而不返回1083错误,如何使用else?

时间:2009-10-03 03:02:39

标签: flash actionscript-3 flash-cs3

我在AS3中有if / else if / else if / else if / else语句。

这是一个从xml文件中读取日期的日历。 if / else if / else语句根据日期是否有事件以及日期是过去/现在还是将来来控制日期的外观。 MouseEvent是一个显示事件信息的工具提示。

最后一部分是

else {
 var thisday:String = "<b><font color=\"#666666\" size=\"9\"> <u><font size=\"12\"> -</font> " + yy + " <font size=\"12\">-</font> " + GlllStringUtil.checkDigits((mm + 1).toString()) + " <font size=\"12\">-</font> " + i.toString() + " <font size=\"12\">- </font></u></font></b> ";
 myCLabel = new ICLabel(); 
 myCLabel.date.htmlText = GlllStringUtil.checkDigits(i.toString());
 myCLabel.date.background = false;
 myCLabel.date.textColor = "0x666666";
 myCLabel.date.autoSize = TextFieldAutoSize.CENTER;
 myCLabel.date.selectable = false;
 myCLabel.date.mouseEnabled = true;
 myCLabel.y = 0;
 myCLabel.x = 25 * (i - 1);
 myCLabel.name = i.toString();
 myCLabel.data = thisday;
 myCLabel.addEventListener(MouseEvent.MOUSE_OVER, myCLabel_mouse_over);
 myCLabel.addEventListener(MouseEvent.MOUSE_OUT, myCLabel_mouse_out);
 calendarHolder.addChild(myCLabel);
}

如果我在声明中重复这个,如果{var ...

,我会得到1084使用else

我可以使用else,但是如果我使用if / else开始下一部分并且当它完成我需要的时候 - 外观会被最后的if / else覆盖。

我正在尝试这样做,因为对于未来日期的出现只有一个声明,这意味着如果有未来事件 - 它不会突出显示。

如果{var,没有它返回1084?

,如何使用else重复内部

(由于我对AS3知之甚少,所以非常感谢任何帮助。)

-

更新

非常感谢您的回复。

该文件是一个.as而且它很长,所以我所做的就是上传它here 作为.txt文件。还有2个小的GIF图像试图展示我正在努力实现的目标。 (您会注意到(在图像中)工具提示出现在突出显示的日期上,否则未来日期不会突出显示,因此除非您将鼠标悬停在某个日期之外,否则无法确定是否存在事件。)

我希望没关系。

我确实检查过以确保在发布之前我没有错过结束支架,但我认为错误超出了我的理解。

2 个答案:

答案 0 :(得分:5)

1084是表示语法错误的错误。你错过了关闭支撑或类似的东西。如果您想获得更精确的答案,请发布完整的功能代码:)

答案 1 :(得分:0)

看起来您正在修改下载的库。我想我理解你的问题,遗憾的是,用完全解决方案很难帮助你。

这些模块遵循以下模式:

if( /*<some condition>*/ ) {
    // create a specific type of Label
}
else if( /*<another condition>*/ ) {
    // create a different type of Label
}
else if( /*<yet another condition>*/ ) {
    // create yet another type of Label
}
else {
    // create a default type of Label
}

这是if语句的工作方式。只有一个else,它必须在最后才会出现。它处理所有ifelse if条件无法匹配时发生的情况。这有点像“最后的手段”行动。

您在链接的代码的注释中说:“如果没有事件,此块会控制日期的样子。”并且您想要添加一个在有事件时处理的块。这意味着您要添加新的else if。为此,您需要来提供条件。

if( /*<some condition>*/ ) {
    // create a specific type of Label
}
else if( /*<another condition>*/ ) {
    // create a different type of Label
}
else if( /*<yet another condition>*/ ) {
    // create yet another type of Label
}
// Here you need a new condition
else if( /*<some condition that evaluates to true when there are events>*/ ) {
    // create a label styled to show off events
}
else {
    // create a default type of Label
}

代码比我愿意投入更复杂一些,以帮助您确定如何编写一个条件,当某个日期有事件时,该条件的评估结果为true。但是,与我所显示的表格相符的声明应该可以解决你的1084错误。