A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: import and AS 2.0

  1. #1
    Senior Member sprout74's Avatar
    Join Date
    Oct 2000
    Posts
    134

    import and AS 2.0

    I am authoring an application using Flash MX Pro, 7.0.1.

    I am using the import statement from AS 2.o inside of different classes in different packages.

    But when I do a syntax check (Ctrl + t) I get all kinds of errors saying that the imported classes do not match the references in the code, or that the class could not be loaded.

    Now, I have checked the folder structure a hundred times, as well as the names of the classes and their AS files and they are all correct.

    So why am I getting these errors when I check the code in the ActionScript editor?

    thanks,

    sprout
    "If the implementation is hard to explain, it's a bad idea.
    If the implementation is easy to explain, it may be a good idea."
    from The Zen of Python (by Tim Peters)

  2. #2
    FK Slacker
    Join Date
    Jun 2000
    Location
    vancouver
    Posts
    3,208
    Have you checked that the class names include the full classpath? ie: if you have a class named myClass in a folder named myPackage, than the class file needs to look like:

    class myPackage.myClass{

    //class definition

    }

    if you just have

    class myClass{
    //etc
    }

    And then try to import myPackage.myClass you will get errors...

    K.

  3. #3
    Senior Member
    Join Date
    Jul 2002
    Location
    Slovenia
    Posts
    193
    I've also experienced such problems... These problems are related to the classpath, but they'll get sorted when you finally use the classes in your project.

    Suppose you have this code in file "MyClassA.as" in the directory "Classes/SomeNamespace/" (again suppose your classpath references the "Classes/" directory):
    code:
    class SomeNamespace.MyClassA{
    // The code
    }



    Now, if you put another class "MyClassB.as" in the same directory "Classes/SomeNamespace/":
    code:
    import SomeNamespace.MyClassA
    class SomeNamespace.MyClassB{
    // etc...
    }



    The MyClassB references MyClassA from the SomeNamespace, not knowing that it is in the same directory, the simple Ctrl+t will return an error, because SomeNamespace was not found in any of the relative classpaths... I have never bothered though, but try using absolute classpaths to solve this annoying problem - I wouldn't do it though

    Nevertheless, if you incorporate the code into your flash document, MyClassB will work ok.

    Best regards
    Last edited by MatejKo; 06-22-2004 at 04:30 PM.

  4. #4
    Senior Member sprout74's Avatar
    Join Date
    Oct 2000
    Posts
    134
    yeah, I have the full class path for the class.

    So if this is the directory structure of the project:

    myFla.fla
    <folder1>
    |------ myClass.as
    <folder2>
    |------ myImport.as

    so, in the ActionScript editor I am editing myClass.as:

    import folder2.*;

    class folder1.myClass {
    public function myClass() {}
    }

    ???
    "If the implementation is hard to explain, it's a bad idea.
    If the implementation is easy to explain, it may be a good idea."
    from The Zen of Python (by Tim Peters)

  5. #5
    Senior Member sprout74's Avatar
    Join Date
    Oct 2000
    Posts
    134
    thanks for the reply MatejKo.

    so you are saying that once I publish the SWF this problem will go away?

    It is just a problem in the Flash IDE?
    "If the implementation is hard to explain, it's a bad idea.
    If the implementation is easy to explain, it may be a good idea."
    from The Zen of Python (by Tim Peters)

  6. #6
    Senior Member
    Join Date
    Jul 2002
    Location
    Slovenia
    Posts
    193
    Yes, this is what I have tried to explain in the previous post... I hope you understand what I wanted to say

    best regards

  7. #7
    Senior Member sprout74's Avatar
    Join Date
    Oct 2000
    Posts
    134
    yes, I understand and thanks!

    So does this mean I have to edit the Publish Settings for the FLA that uses these classes?

    And if yes, do I use the full path to the directory the files live in like:

    c:\myProject\myClasses\myNet

    or can I use dot syntax using the FLA as the root, so:

    myClasses.myNet


    or do I leave the classpath settings alone?
    "If the implementation is hard to explain, it's a bad idea.
    If the implementation is easy to explain, it may be a good idea."
    from The Zen of Python (by Tim Peters)

  8. #8
    Senior Member
    Join Date
    Jul 2002
    Location
    Slovenia
    Posts
    193
    Ok. I have the solution:

    Here it's how it goes (for each of your ASes that do not work):

    1. open your .as in Flash MX 2004
    2. Select Edit->Preferences... (Ctrl-U)
    3. In the dialog box select the ActionScript tab and in the Language group box press the "ActionScript 2.0 settings..." button
    4. Add an absolute path to the root namespace (this means if you are importing "MyNS.SomeClass" from the "D:\MyProject\classes\MyNS\" directory, you will add this absolute path: "D:\MyProject\classes\" without the namespace's name subdirectory!).

    Best regards

  9. #9
    Senior Member sprout74's Avatar
    Join Date
    Oct 2000
    Posts
    134
    thank you!!

    That is an excellent solution!

    And a perfect description of how to do it.

    Thank you so much. This was a real problem for me because I like to develop in an OO way, but having the syntax checker throwing errors when I just wanted to make sure I had the right number of brackets was a real pain.

    Thanks again,

    sprout
    "If the implementation is hard to explain, it's a bad idea.
    If the implementation is easy to explain, it may be a good idea."
    from The Zen of Python (by Tim Peters)

  10. #10
    derD
    Join Date
    Jul 2005
    Posts
    1

    Still having problems

    Hello
    Good to know there is s.th. like "ctrl+u", but I have still the same problem for one class. It cannot be loaded.

    I followed up the classpath in "Locale Settings/.../Classes/aso" and did not found an aso File for this class. All other classes where compiled to "aso" but this one not. When I check this class with "ctrl+t" I don`t get any errors.

    But it cannot be loaded...

    Any ideas?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center