Results 1 to 6 of 6

Thread: packages cannot be nested error (1037)

  1. #1
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Question packages cannot be nested error (1037)

    I am practicing from a book and places the script in a keyframe in a designated script layer

    I have gone over it a few times and can't figure out what
    1037: packages cannot be nested means.

    here is the code:

    package {
    import flash.display.Sprite;
    import flash.events.Event;

    public class Velocity extends Sprite {
    private var _sprite:Sprite;
    private var _vx:Number = 3;

    public function Velocity () {
    _sprite =new Sprite();
    _sprite.graphics.beginFill(0x0000ff, 100);
    _sprite.graphics.drawCircle(0, 0, 25);
    _sprite.graphics.endFill();
    _sprite.x =50;
    _sprite.y =100;
    addChild (_sprite);
    addEventListener(Event.ENTER_FRAME, onEnterFrame);
    }
    public function onEnterFrame(event:Event):void{ _sprite.x += _vx;
    }
    }
    }


    If it works it will create a shape and animate it.
    Any suggestions?

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Did you declare a package in the code on the Actions tab in Flash?

    If so, this won't work. Flash creates a package of its own that contains your Action tab code.

    If you want to use a package, you can put the class into an .as file and then use that class as the Document class for the .fla.

  3. #3
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default

    As a matter of fact that was my first mistake -so now I have a the code saved as script.as

    in a folder called com

    the syntax I used is

    import com.sript; -no good so I tried adding a function to call it

    var myscript:script = script();

    I think I have the general idea but the syntax is bad -am I close?

  4. #4
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Code:
    import com.sript;
    1. I assume the missing "c" is just a typo as you're typing it in the forum
    2. Did you assign the folder to your class path? or is the com folder in the same directory as your .fla? You need to do one of the two.

    The other option would be to declare script.as as your Document class.

  5. The Following User Says Thank You to Medyman For This Useful Post:

    evan (04-08-2008)

  6. #5
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default

    yeah that was a typo in the forum -but I realised I can do it more than one way ie nmae it as a class, and save it in a folder identical to it's name

    import script;

    if it's in the same folder as the fla

    import script.as;

    ..if I have more than one sript in the folder named 'com'

    then I THINK it's

    import com.script; import com.script.as; or just call all the scripts as in

    import com.*;

    I think that covers it. Unless I missed something in that I need to assign a "class path"

    Why so many ways to do the same thing?

  7. #6
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Yes, the example import statements you mention are correct. If you're only importing a particular AS file, then you have to add the extention and call the path relative to the .fla.

    If you have a bunch of classes in a folder called com/math/ (path relative to .fla), than you would do something like
    Code:
    import com.math.*
    This imports all of the classes within the com/math/ folder. Flash does this in an intelligent way, though. So if you only use 1 out of 20 classes in that folder, it will only compile the relevant class. So, you don't have to worry about importing things you don't need.

    I think that covers it. Unless I missed something in that I need to assign a "class path"
    The class path should only be declared if you want to use the same classes across multiple projects. If you have 20 projects each using the same class, it's not the best idea to copy the same class into 20 different folders. This is when the class path declaration comes in handy. You can set a default path to where your classes lie (tutorial). The syntax for calling that class (import com.math.*) is still the same but that file no longer has to be in each of your 20 directories, just in the central location that you've specified.

    This is a global change. It's not done on a project by project basis. So you set it once, and until you change it, stays that way. You can also declare more than one class path. So, you can have different folders where you put your classes.

    In Flash CS3, you have to specify different paths for AS 2.0 classes and AS 3.0 classes.

    Why so many ways to do the same thing?
    As it turns out, yes. The generally accepted way to just import one AS file in an OOP design/application, is to declare it as the Document class (tutorial).

Bookmarks

Posting Permissions

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