views:

792

answers:

2

I have an if/else if/else if/else if/else statment in AS3.

It's a calendar that reads in dates from an xml file. The if/else if/else statements controls the look of a date according to whether it has an event, and whether it's past/present or future. The MouseEvent is a tooltip which shows the Event information.

The last section is

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

If I repeat this inside the statement I get a 1084 for using else if { var...

I can use else, but then if I start the next section with if/else and while it does what I need - the appearance is overriden by this last if/else.

I am trying to do this because there is only one statment for the appearance of future dates, which means that if there is a future event - it's not highlighted.

How can I repeat it inside using else if { var, without it returning 1084?

(Any assistance would be greatly appreciated as I have very little knowledge of AS3.)

--

Update:

Thank you so much for your reply.

The file is a .as and it's quite long so what I've done is upload it here as a .txt file. There are also 2 small gif images to try and demonstrate what I'm trying to acheive. (You'll notice (in the image) the tool tip appears over a highlighted date, but otherwise Future Dates aren't highlighted therefore you can't actually tell if there is an event unless you mouse over a date.)

I hope that is okay.

I did check to make sure that I didn't miss the closing brace before I posted but I think the error is beyond my understanding.

+3  A: 

1084 is an error indicating bad syntax. you've missed closing a brace or something along those lines. post the complete function code if you want to get a more precise answer :)

JStriedl
A: 

It looks like you are altering a library you downloaded. I think I understand your problem, unfortunately it will be difficult to help you with an exact solution.

The blocks follow this pattern:

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
}

This is the way if statements work. There can be only one else and it has to come right at the end. It handles what happens when all of the if and else if conditions fail to match. It is kind of like the "last resort" action.

You say in the comments of the code you linked: "This block controls what the dates look like if there are NO Events." and you want to add a block that handles when there are events. That means you want to add a new else if. To do so you need to provide a condition.

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
}

The code is a little more complicated than I am willing to invest to help you determine how to write a condition that evaluates to true for a particular date when there are events for that date. But a statement that matches the form I have shown should work and get around your 1084 error.

James Fassett
Thank you so much for taking the time to look at my problem. I apologise for such a late response, the answer notification must have gone into the spam.I actually had tried several times to add a new statement, but as I mentioned, my knowledge is limited. However you've confirmed what I thought would probably be the case. So, thank you again.
Tina