0

我在 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);
}

如果我在语句中重复这一点,我会得到一个 1084 用于使用 else if { var...

我可以使用 else,但是如果我使用 if/else 开始下一节,并且它执行我需要的操作 - 外观会被最后一个 if/else 覆盖。

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

如何使用 else if { var 在不返回 1084 的情况下重复它?

(任何帮助将不胜感激,因为我对 AS3 知之甚少。)

--

更新:

非常感谢你的回复。

该文件是 .as 并且它很长,所以我所做的就是将它 作为 .txt 文件上传到这里。还有 2 个小 gif 图像可以尝试展示我想要实现的目标。(您会注意到(在图像中)工具提示出现在突出显示的日期上,但未来日期不会突出显示,因此除非您将鼠标悬停在日期上,否则您实际上无法判断是否存在事件。)

我希望没关系。

在发布之前,我确实检查过以确保我没有错过右括号,但我认为这个错误超出了我的理解。

4

2 回答 2

5

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

于 2009-10-03T06:13:52.857 回答
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
}

该代码比我愿意投资的代码要复杂一些,以帮助您确定如何编写一个条件,当该日期有事件时,该日期的计算结果为真。但是与我展示的表格相匹配的声明应该可以解决您的 1084 错误。

于 2009-10-06T10:32:02.580 回答