1
votes

I am having a very strange issue with the flex compiler (using Flash Builder 4.5) that I have never come across before.

I am trying to create an instance of a class (that exists in the same package) and the compiler will not recognize the class as a compile-time constant, but only in instance methods. Class methods (static) will compile without issue.

This class is being used all over the place without issue. Just in this one place it will not compile in instance methods. Makes no sense.

I have tried everything I can think of...

  • Added an import for UploadDate (even though the class is in the same package)
  • Clean built the project (and all parent/sub projects)
  • Deleted code model cache (.metadata/.plugins/com.adobe.flexbuilder.codemodel/*)
  • Deleted all generated assets cache (.../com.adobe.flexide.editorcore/GeneratedAssets/*)
  • Compiled with different flex sdk's (3.2, 3.5, 3.6)

Here is the code:

package classes
{
    import classes.UploadDate;

    [Bindable]
    public class UserImages {
        ....

        //this compiles with no errors
        public static function classMethod():void {
            var ud:UploadDate = new UploadDate();
        }

        //this will not compile
        public function instanceMethod():void {
            //1046: Type was not found or was not a compile-time constant: UploadDate
            var obj:UploadDate = new UploadDate();
        }

        //this is the ugly workaround I am currently using (works fine at Runtime)
        public function hackyMethod():void {
            var Def:Class = getDefinitionByName("classes.UploadDate") as Class;
            var obj:* = new Def();
        }
    }
}

And the UploadDate class:

package classes
{
    [Bindable]
    public class UploadDate {
        public var date:String;
        public var numImages:int;

        public UploadDate() {
        }
    }
}

Has anyone seen this before?

Thanks, Matt

1
That's very strange indeed, I'd be curious to know why it doesn't compile. Have you tried deleted your .aso files? I'm not sure where they are generated by Flash Builder, they might be in one of the folders you've already deleted. Also, since Flex relies on JRE, maybe JRE is the one caching something it shouldn't cache. Would restarting your computer make any difference?laurent
public UploadDate() { is not valid and won't compile. But this is probably not the problem?Kaken Bok
I encountered a problem like that when using static constants in method signatures or instance properties. The solution here was to rename the class which contains the constants so that it was alphabetically ordered before all other classes. Try to rename UploadDate to AUploadDate.Kaken Bok
Perhaps it's a problem with the package or class names, try to rename the package from classes to something else and do the same for UploadDatecmann
I noticed [Bindable] right above you class statement take that outThe_asMan

1 Answers

0
votes

"I encountered a problem like that when using static constants in method signatures or instance properties. The solution here was to rename the class which contains the constants so that it was alphabetically ordered before all other classes. Try to rename UploadDate to AUploadDate." – Jens Struwe Aug 18 '11 at 7:12