A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Simple switch statement

  1. #1
    Member
    Join Date
    Apr 2003
    Location
    Orem Utah
    Posts
    34

    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”

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    try

    public var dayNum:int = 1;
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    \x3a\x6f\x29
    Join Date
    Sep 2005
    Location
    paris
    Posts
    88
    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

  4. #4
    Member
    Join Date
    Apr 2003
    Location
    Orem Utah
    Posts
    34
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center