12 Replies Latest reply on Nov 13, 2011 9:07 PM by John Hall

    Type was not found or was not a compile-time constant:Number

    nathanp812

      Hi everyone,

       

      I am new to flex and have spent the last few weeks diving in with Flex 4.5, Amethyst designer and WebORB .NET.

      Everything is going pretty well, I have a services DLL set up that I use remoting to pull down an array list of items from a database and am able to display those records.

       

      The issue arises when I try and reference the WebORB generated data model classes in my mxml page. 

      The minute I add a reference to any one of these classes the entire project no longer compiles with the following error.

       

      Type was not found or was not a compile-time constant:Number

       

      I am a little confused.  I thought Number was part of the Flex base classes and it was included by default?

      To add to my confusion if I add a reference to Number in my mxml code no error is thrown, yet the compiler throws an error pointing to Number as the culprit when I try to add a reference to my class.

       

      var t:Number;  // This works fine.

      var n:MyCustomClass;  // Compile error thrown

       

      Is there something I need to include in my build settings?

       

      Any assistance would be greatly appreciated. 

       

      Thanks

        • 1. Re: Type was not found or was not a compile-time constant:Number
          John Hall Level 4

          And you've imported that class to the file with the error?

          • 2. Re: Type was not found or was not a compile-time constant:Number
            nathanp812 Level 1

            Hi, thanks for the quick reply.

             

            Yes, I added a single import statement to where my classes reside.

             

            import ARISFlexService.AAP.vo.*

             

            Which I assume covers everything in the namespace vo but the problem still persists.

            Do I need to import each class as a separate import statement?

             

            I should point out that these classes have references to other classes and it looks like all the imports for each of these classes have been generated.

            • 3. Re: Type was not found or was not a compile-time constant:Number
              John Hall Level 4

              No you shouldn't have to import each class, just making sure you have the namespace covered (subfolders obviously aren't covered so they'd have to be separate).

               

              So when you look at the typing of the variable in your declarations at the top, there's no yellow or red squigley line indicating a problem linking, right? when you put the cursor on the type and press control-space, it shows what you would expect?

              • 4. Re: Type was not found or was not a compile-time constant:Number
                nathanp812 Level 1

                No, there are no code syntax warnings that would make me think that there

                is a problem with the classes,namespace or code, the intellisense works

                fine.

                All my classes are in folders that correspond to the namespaces as well as

                I understand that is a requirement.

                 

                So I am really at a loss as to what could be causing it, it is quite

                confusing.

                The only thing I can think of is perhaps the classes are too complex for

                flex, perhaps I need to write the classes manually and simplify their

                structure (which defeats the purpose of using web orb).

                • 5. Re: Type was not found or was not a compile-time constant:Number
                  John Hall Level 4

                  I've never heard of a class being too complex to handle. Sure it might cause a real performance hit but that would be all I would expect.

                   

                  Do you have the source code for the custom class? If so, have you debugged the code with the line debugger and find out what line it bombs on? If it won't compile at all, try changing your custom class to a generic object and see if it'll at least let you compile and step through.

                  • 6. Re: Type was not found or was not a compile-time constant:Number
                    nathanp812 Level 1

                    Hi John,

                     

                    Sure, here is the class that causes the error.  The compiler very unhelpfully tells me the error occurs on Line 1, Column 2, which is actually part of the code comments.

                    I am pretty sure it has something to do with the Number type because if I change all references in the class from Number to int everything compiles properly.

                    It is almost like the package does not know how to find the Number type.

                     

                    /*******************************************************************

                    * Race.as

                    ********************************************************************/

                    package ARISFlexService.AAP.vo

                    {

                      import flash.utils.ByteArray;

                      import mx.collections.ArrayCollection;

                      import ARISFlexService.AAP.vo.Distance;

                      import ARISFlexService.AAP.vo.Meeting;

                      import ARISFlexService.AAP.vo.RaceRestriction;

                      import ARISFlexService.AAP.vo.*;

                        [Bindable]

                        [RemoteClass(alias="ARISFlexService.AAP.Race")]

                        public class Race

                        {

                            public function Race(){}

                       

                            public var Id:Number;

                            public var Group:int;

                            public var GroupSpecified:Boolean;

                            public var Division:String;

                            public var MinHcpWeight:Number;

                            public var MinHcpWeightSpecified:Boolean;

                            public var Name:String;

                            public var NominationNumber:String;

                            public var Number:int;

                            public var StartTime:String;

                            public var WeightType:String;

                            public var Classes:Array;

                            public var Distance:ARISFlexService.AAP.vo.Distance;

                            public var DistanceReference:Object;

                            public var Horses:Array;

                            public var Meeting:ARISFlexService.AAP.vo.Meeting;

                            public var MeetingReference:Object;

                            public var Prizes:Array;

                            public var RaceRestriction:ARISFlexService.AAP.vo.RaceRestriction;

                            public var RaceRestrictionReference:Object;

                        }

                    }

                     

                    I assume the Number is chosen for the datatype because of the fact it is a long datatype in .NET so the Number datatype would be big enough to accomodate it.

                    • 7. Re: Type was not found or was not a compile-time constant:Number
                      John Hall Level 4

                      Pretty unusual in Actionscrilpt to name variables with capital letters, which is usually reserved for classnames. Because of that, I can't help but think that the variable called Number, which is declared as an int, is probably causing the issue.

                      • 8. Re: Type was not found or was not a compile-time constant:Number
                        nathanp812 Level 1

                        It is a class name.  Apparently it is meant to be used in situations where

                        the values required exceed those of int.

                        So I am sure I need it as a reference as the database that this class

                        references has over 20 million records and counting.

                        If I switch to an int now, later on I may find myself in a situation where

                        the int wont hold the amount of data required and will cause some issues

                        later.

                        The strange thing is that I have searched high and low on the net for

                        people having the same issue and cannot find any specifically relating to

                        Number type.

                         

                        http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Number.html

                        • 9. Re: Type was not found or was not a compile-time constant:Number
                          nathanp812 Level 1

                          Ok, my workaround for now is just to change all references to Number in the

                          generated class to Object.

                          Be4cause I know what the datatype is I should be able to convert to a

                          number as required.

                           

                          It is still not really what I would call a solution and as a developer I do

                          not like it when problems occur to which I cannot find at least a reason as

                          to why they are occurring.

                          • 10. Re: Type was not found or was not a compile-time constant:Number
                            John Hall Level 4

                            Just to be sure we're talking about the same, I'm talking about what looks like a variable name in the declarations:

                             

                              public var Name:String;

                              public var NominationNumber:String;

                              public var Number:int;

                              public var StartTime:String;

                              public var WeightType:String;

                            • 11. Re: Type was not found or was not a compile-time constant:Number
                              nathanp812 Level 1

                              Hi John,

                               

                              I cannot believe I missed that one!  I changed Number:int to

                              number:int and the problem seems to have been resolved.

                               

                              Being from a C# background there is no Number class for holding data types

                              out of the box so that works perfectly on the C# side of things but it

                              obviously would be invalid for the flex compiler.

                              It would be the same if I made a variable name on the C# side of things

                              called int - the compiler just would not allow it (but it would tell me as

                              soon as I did it).

                               

                              The code is auto-generated so I surprised that the WebORB codegen would be

                              smart enough to work out whether or not a variable name conflicted with a

                              base class or data type.

                               

                              Thanks so much for your assistance John.  You are a life saver! 

                               

                              Cheers

                              • 12. Re: Type was not found or was not a compile-time constant:Number
                                John Hall Level 4

                                Great. Hope you don't hit any more roadblocks.