6 Replies Latest reply on Dec 20, 2010 5:10 AM by userben

    I can't seem to import as classes from other files

    userben Level 1

      This is driving me crazy, I've been trying to resolve this on my own for ages, and I've reviewed a lot of different materials, but I still can't seem to just import some external actionscript classes correctly.

       

      I'm using Flash Builder 4 with the Flex 4 SDK on mac osx 10.6

       

      the class I'm trying to import (I'll call it DesiredClass) is in a folder like this

       

      /libraries/com/foreignproject/com/foreignproject/DesiredClass.as

       

      within the class itself, the package declaration looks like this (I left all the guts out for clarity):

       

       

      ---------------------------------------------------------------------

       

      package com.foreignproject

      {

          import flash.display.Sprite;


          public class DesiredClass extends Sprite

          {

              public function DesiredClass()

              {

              }

          }

      }

       

      ---------------------------------------------------------------------

       

      I'm working on a totally different actionscript file at

      /Users/username/Documents/Adobe Flash Builder 4/TestProject/src/TestProject.as

       

      in this file I try to import the DesiredClass:

      ---------------------------------------------------------------------

      package

      {

           import com.foreignproject.DesiredClass;

           import flash.display.Sprite;


           public class TestProject extends Sprite

           {

                public function TestProject()

                {

                var neatClass:DesiredClass = new DesiredClass();

                }

           }

      }

       

       

       

      ---------------------------------------------------------------------

      And then I try to add the class I want to the source path.
      I've tried adding each folder to the source path separately:

      /libraries/com/foreignproject/com/foreignproject/DesiredClass.as

      /libraries/com/foreignproject/com/foreignproject/DesiredClass.as

      /libraries/com/foreignproject/com/foreignproject/DesiredClass.as

      /libraries/com/foreignproject/com/foreignproject/DesiredClass.as

      /libraries/com/foreignproject/com/foreignproject/DesiredClass.as

       

      If I choose the libraries folder or either of the com folders then an error shows up in the TestProject.as file, saying:

      Definition com.foreignproject:DesiredClass could not be found.

       

      But f I choose either of the foreignproject folders then an error shows up in the DesiredClass.as file saying:

      a file found in a source-path must have the same package structure 'com.foreignproject', as the definition's package, ".

      What am I doing wrong? Please help. I bought a book on actionscript, started doing the flex-in-a-week series, read numerous online discussion boards, and I still can't import these classes.
      Thanks in advance.
        • 1. Re: I can't seem to import as classes from other files
          Lee Burrows Level 4

          try adding a source folder path rather than linking to the .as file itself.

           

          folder path of libraries/com/foreignproject is what you need i think

          • 2. Re: I can't seem to import as classes from other files
            userben Level 1

            Hi Lee,

             

            Thanks for responding!

            I don't quite understand your answer.

            Are you suggesting that I insert a different import statement?:

             

            import libraries.com.foreignproject

             

            or are you suggesting that I add the foreignproject folder to the source path?

            I have already tried adding the foreignproject folder to the source path, but this results in the same "not found" error.

            • 3. Re: I can't seem to import as classes from other files
              Lee Burrows Level 4

              yep, i meant add folder to source path.

              • 4. Re: I can't seem to import as classes from other files
                userben Level 1

                Yeah I still get a "does not exist" error.

                 

                Below are the steps I use to add it to the source path:

                 

                 

                right click on Main Project Package in Package Explorer

                    select "Properties"

                        select "ActionScript Build Path"

                            click "Source path"

                                click "Add Folder"

                                    click "Browse…"

                                        browse for folder: "libraries/com/foreignproject"

                                        it gets translated automatically to:

                                            "$[com]/foreignproject"

                                        click "Choose"

                                    click "OK"

                                click "OK"

                 

                That is how I add a folder to the source path.

                Please let me know if I'm not doing that right.

                 

                 

                Thanks

                • 5. Re: I can't seem to import as classes from other files
                  Lee Burrows Level 4

                  maybe FB is getting confused by the folder structure (/libraries/com/foreignproject/com/foreignproject/) as you have repeated the com/foreignproject path (when it internally replaces $[com] with the full path?

                   

                  can you overwrite "$[com]/foreignproject" and replace it with a full path (eg c:/folder/path/etc/libraries/com/foreignproject/com/foreignproject/ ?

                  • 6. Re: I can't seem to import as classes from other files
                    userben Level 1

                    Thanks Lee for your continued help.

                     

                    I tried to manually edit the folder path, but Flash Buider said that it was an invalid path and insisted on inserting "$[com]/foreignproject"

                     

                    So I just moved the folder to eliminate the repeated names, and now the path is:

                    /Users/username/Documents/code/libraries/as/com/foreignproject/DesiredClass.as

                     

                    but I still run into the same problems, either it says that "DesiredClass cannot be found" (when I select the com folder)

                    or it says that there is an error with the package name in DesiredClass (when I select the foreignproject folder)