7 Replies Latest reply on Oct 17, 2007 1:03 PM by ntsiii

    packages can not be nested

      Heres some of my code. I'm not sure why I'm getting a packages can not be nested error...

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" backgroundColor="#fffffff">
      <mx:Script source="PlayButtonFunctionality.as"/>


      then in PlaybuttonFunctionality.as

      package mine
      import mx.collections.ArrayCollection;

      public class PlayButtonFunctionality {
      var newState:State;
      var playList:ArrayCollection;


        • 1. Re: packages can not be nested
          ntsiii Level 3
          The syntax, "<mx:Script source=" is like an import. the code is physically placed in the main file.

          Since any mxml file becomes its own class, with a package, you can't have the package statement in the source as file.

          You are mixing two different ways to get functionality into the main file.

          If you want to use a class, like PlaybuttonFunctionality, then instantiate the class in the main mxml file, either using mxml tag:
          <PlaybuttonFunctionality id="pb" ..../>

          Or in AS:
          private var PBf:PlaybuttonFunctionality = new PlayButtonFunctionality;

          If youeant to include the functions, do not declare a package or class in the source file, only the functions and vars.

          • 2. Re: packages can not be nested
            grolnb Level 1
            ok i got rid of the package and the class but now i get this error:
            A file found in a source-path must have an externally visible definition. If a definition in the file is meant to be externally visible, please put the definition in a package.
            • 3. Re: packages can not be nested
              <mx:Script source="../mine/PlayButtonFunctionality.as">
              this is as part of mxml file
              no package definition .just declare vars,functions.
              • 4. Re: packages can not be nested
                grolnb Level 1
                Yeah. I've done those things and i still get the above error message. I should also mention im using flex builder 3 beta.

                Any help would be great thanks!
                • 5. Re: packages can not be nested
                  kittuokkade Level 1
                  hello i have tested this sample in flexbuilder3 beta
                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" autoLayout="true" >
                  <mx:Script source="comp/myscript.as"/>
                  <mx:Panel x="0" y="0" width="2000" height="4000" id="mypanel" layout="absolute">
                  <mx:Button x="174" y="86" label="Button" click="init()"/>
                  <mx:TextArea x="247" y="87" text="{str}" height="25"/>

                  myscript.as is as follows

                  // ActionScript file
                  public var str:String;

                  public function init():void{
                  str="Hello ActionScript";

                  • 6. Re: packages can not be nested
                    levancho Level 3
                    what you AS file look like ?

                    and can you paste exact error with error code please?
                    • 7. Re: packages can not be nested
                      ntsiii Level 3
                      Sounds like you are trying to instantiate the myscript.as file as a component somewhere. It can't be both an included file and a component.