A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: #include error

  1. #1
    Senior Member
    Join Date
    Jul 2008
    Posts
    128

    #include error

    #include "ActionScript/cObject.as"

    Thats my line of code. The error is:
    1093: Syntax error.

    I don't think its wrong but it must be. Not sure why though.

  2. #2
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    In AS3 you do not use #include.

    In AS3 it is simply:

    include "[path]filename.as"

    Try that
    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


  3. #3
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Thanks!!! Works great but now I have another problem. Once that was fixed I received another error.

    1131: Classes must not be nested.

    I don't a nested class

    class cObject
    {
    // Member vars

    //=======================================
    // Constructor
    //
    // Purpose: Simple Constructor.
    //=======================================
    public function cObject():void
    {
    }
    }

    any ideas?

  4. #4
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    Are you doing the include on a timeline in Flash?

    Cause if you are, you cannot define a class inside of the timeline.
    If you want to use the class cOjbect, don't include it, and use the import statement.

    Then, when you want to use the cObject, create a new one

    var ex:cObject = new cObject();
    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


  5. #5
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    I have cObject as a external .as file and I include it so I can create the cObject.
    I have even tried to wrap it in a package but it tells me packages can't be nested.
    No clue... and yes I am including it on my first frame of my actions layer.
    Last edited by Xeris2; 01-05-2009 at 03:02 PM.

  6. #6
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    the include statement, is not meant for using class objects.

    Make sure this is how your class looks.
    Every class you create must be part of a package.
    If you are not using a folder structure for your code, we will use the unnamed package. Since we are using the unnamed package, also make sure that cObject.as is in the same directory as your .fla
    PHP Code:
    package 
    {
        public class 
    cObject
        
    {
            
    // Member vars
            //=======================================
            // Constructor
            //
            // Purpose: Simple Constructor.
            //=======================================
            
    public function cObject():void
            
    {
                
    //code
            
    }
        }

    Because the class is in the unnamed package, we don't need an import statement, which is what you use to make sure the .fla knows where to find the class file. Another problem, was that you MUST declare a class as public. If not it is treated as private.

    Now, if you place in your code

    var test:cObject = new cObject();
    trace(test);

    That should trace out [Object cObject]
    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


  7. #7
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    What if I put all my .as file in a folder called ActionScript?
    Would my package then be: package ActionScript? or what would I have it be because I still have the same issue.

  8. #8
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    Yes, the package name matches the folder structure where your code is placed.

    Normally the convention is to not use a capitol letter for package names.
    So if your cObject class is in the folder ActionScript, your class would have this

    package ActionScript
    {
    public class cObject {



    and in your timeline, you would need the import statement.

    import ActionScript.cObject;
    var test:cObject = new cObject();
    trace(test);

    I do suggest changing the folder name to start with a lower case letter. It helps differentiate between classes (which normally start with an uppercase letter) and packages (which start with lowercase letters).
    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


  9. #9
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    I still can't seem to get it to compile without the error. Probably something stupid on my part.
    1037: Packages cannot be nested.

  10. #10
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    If you could post exactly what you have in the timeline, inside the cObject class file, as well as the folder structure for the pacakages, we might be able to figure it out.
    Don't post everything, just the barebones. I think the issue might just be a spelling problem...
    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


  11. #11
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Timeline:
    include "ActionScript/cTimer.as"

    cObject.as:
    package ActionScript
    {
    //=======================================
    // cObject
    //
    // Purpose: Simple class
    //=======================================
    public class cObject
    {
    //=======================================
    // Constructor
    //
    // Purpose: Simple Constructor.
    //=======================================
    public function cObject():void
    {
    }
    }
    }

    I have my .fla and ActionScript Folder all in the same folder.

    Sorry for not putting the code in code blocks never new how to do it lol.

  12. #12
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Timeline:
    include "ActionScript/cTimer.as"

    cObject.as:
    package ActionScript
    {
    //=======================================
    // cObject
    //
    // Purpose: Simple class
    //=======================================
    public class cObject
    {
    //=======================================
    // Constructor
    //
    // Purpose: Simple Constructor.
    //=======================================
    public function cObject():void
    {
    }
    }
    }

    I have my .fla and ActionScript Folder all in the same folder.

    Sorry for not putting the code in code blocks never new how to do it lol.

  13. #13
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    Like I said before, you are NOT using the include statement.

    in the timeline, change it to
    import ActionScript.cObject;

    when using the import statement, you do not place quotes around the class name, and there must be a semi-colon
    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


  14. #14
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    lol sorry about that, works now. So why is it I don't need the include statement? I thought a include statement was ment for external files, while import was for classes that are declared within the FLA.

  15. #15
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    include is meant for code, that is not in a class format.

    So you could have a few methods and variables in a file called goodCode.as
    The code inside the .as file should not have any class declaration or package.
    It's like code that you write in the timeline.
    Using the include statement will take the code in that file, and essentailly add that code to the timeline where you include it.

    so if you have this in goodCode.as:
    And exactly that.

    PHP Code:
    var cool:Number 3.9204
    var round:int 4;

    function 
    makeCool ():void {
        
    //I made something cool!

    Then in your timeline you have:

    PHP Code:
    stop();

    var 
    userID:int 4183;

    include 
    "goodCode.as"

    function eliminate():void {
        
    //destroyed!


    Once, compiled, what you have effectivley done is this in your timeline:
    PHP Code:
    stop();

    var 
    userID:int 4183;

    // this is where the include statement used to be
    var cool:Number 3.9204
    var round:int 4;

    function 
    makeCool ():void {
        
    //I made something cool!
    }
    //

    function eliminate():void {
        
    //destroyed!


    To get a better wording for it, look here for more info on inlcude and import
    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


  16. #16
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    ic ic, thanks a bunch.

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