|
-
Simple switch statement
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
PHP 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?
“the first step to eternal life is you have to die”
-
Senior Member
try
public var dayNum:int = 1;
- The right of the People to create Flash movies shall not be infringed. -
-
It has to be done like this:
Code:
<?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
-
yeah, that was it. thanks. I did not know that switch statements have to be in a function. ok, good to know.
Thanks!!
“the first step to eternal life is you have to die”
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|