;

PDA

Click to See Complete Forum and Search --> : Simple switch statement


king44444
08-28-2006, 04:52 PM
I’m having problems getting a simple switch statement working. I’m doing this in Flex 2.0, so that might be the problem, but here is the code

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
public var dayNum:Number = 1
switch(dayNum) {
case 0:
trace("Sunday");
break;
case 1:
trace("Monday");
break;
case 2:
trace("Tuesday");
break;
default:
trace("Out of range");
}

]]>
</mx:Script>
</mx:Application>



Flex is giving this error:

1120: Access of undefined property dayNum.


Any ideas?

cancerinform
08-28-2006, 05:06 PM
try

public var dayNum:int = 1;

joa__
08-28-2006, 07:24 PM
It has to be done like this:


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="main()">
<mx:Script>
<![CDATA[
private static var dayNum: Number = 1;

private function main(): Void
{
//switch goes here
}
]]>
</mx:Script>
</mx:Application>


The important thing is, that your application needs some function :)

king44444
08-28-2006, 07:30 PM
yeah, that was it. thanks. I did not know that switch statements have to be in a function. ok, good to know.


Thanks!!