5 Replies Latest reply on Jul 24, 2007 11:21 AM by Jamal_Soueidan

    packages cannot be nested?

    Jamal_Soueidan
      Hello there,

      Yesterday I used the new Flash CS3 with Actionscript CS3, I got allots of newbie problems which I could find a answer for on Google.

      Today I want to try out to develop simple application with Flex 2 and ActionScript, but I faced the same problem as Flash CS3 with ActionScript CS3

      1037: Packages cannot be nested.

      My code looks like this, simple.

      package multiupload {

      public class MultiUpload
      {
      public function tastet()
      {
      trace("ASD");
      }
      }
      }

      and in my Flex application I do this.

      <mx:Script source="./multiupload/MultiUpload.as">
      </mx:Script>
      <mx:Script>
      <![CDATA[
      import multiupload;
      var test:MultiUpload = new MultiUpload();
      ]]>
      </mx:Script>

      Whats wrong with my code? :(

      Regards,
      Jamal
        • 1. Re: packages cannot be nested?
          Robert Hirst Level 1
          You don't need the first script tag, the reference to the class file will be worked out from the names. I think when you import the script you are already in a default package, so when it sees the package declaration in the source file it throws the nesting error.

          I think you also need to import multiupload.*; as you need to import the actual classes not the package itself (similar to Java). Alternatively you could replace * with the specific class name (e.g. "import multiupload.MultiUpload;").
          • 2. Re: packages cannot be nested?
            Jamal_Soueidan Level 1
            Thanks for your answer.

            I have just few questions about this.

            import multiupload.MultiUpload;
            var test:multiupload = new multiupload();

            Why is multiupload not MultiUpload on line 2? Since the class name start with uppercase letter?

            and why cannot I see the functions in the dropdown list when I type

            test(dot)

            and thanks again for your help :)

            regards,
            Jamal
            • 3. Re: packages cannot be nested?
              Robert Hirst Level 1
              It should be the same case as the class name. I think you should get a compiler error when you build that code.

              The easiest way to import and use classes is using autocomplete. I'd scrap the import and the var declaration, then just type "var test:" and when you press colon you should see all the available classes in the project, then if you select your class from this list and press Enter the import statement will be added for you automatically, and var type will be declared in the correct case.

              As for using autocomplete to find methods and vars, you must be inside a function body, as it would be illegal to call any methods otherwise. If you to run some code at start up, you need to place it in the creationComplete of the Application.
              • 4. Re: packages cannot be nested?
                Jamal_Soueidan Level 1
                I'm still new to Flex, so I don't know how to do the auto complete thing you are talking about.

                I'm still facing the problem which is using the class with my application?

                I cannot access any functions from my class?

                Is there any tutorial you can point me :)?

                Thanks again..
                • 5. Re: packages cannot be nested?
                  Jamal_Soueidan Level 1
                  Well, suddenly everything is working :D

                  I hate when this happen hehe