Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 876351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:25:06+00:00 2026-05-15T11:25:06+00:00

In AS3, why do we put our import statements in the package statement, and

  • 0

In AS3, why do we put our import statements in the package statement, and not inside the Class declaration?

This is a typical (but rather pointless) AS3 class:

package my.foo.package
{
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.TimerEvent;
    import flash.utils.Timer;

    public class FooClass extends MovieClip
    {
        public static const EVENT_TIME_UP:String = 'timeUpEvent';

        public function FooClass() 
        {
            var timer:Timer = new Timer(2000, 1);
            timer.addEventListener(TimerEvent.TIMER, timerHandler);
            timer.start();
        }

        private function timerHandler(e:TimerEvent):void 
        {
            dispatchEvent(new Event(FooClass.EVENT_TIME_UP));
        }
    }
}

But why are all the import statements meant to go all the way up there, outside on the Class? The class works perfectly fine when I move the imports to inside the class declaration like below.

package my.foo.package
{
    import flash.display.MovieClip;

    public class FooClass extends MovieClip
    {
        import flash.events.Event;
        import flash.events.TimerEvent;
        import flash.utils.Timer;

        public static const EVENT_TIME_UP:String = 'timeUpEvent';

        public function FooClass() 
        {
            var timer:Timer = new Timer(2000, 1);
            timer.addEventListener(TimerEvent.TIMER, timerHandler);
            timer.start();
        }

        private function timerHandler(e:TimerEvent):void 
        {
            dispatchEvent(new Event(FooClass.EVENT_TIME_UP));
        }
    }
}

It’s only the MovieClip import that needs to be in package, because my class is extending it.

There is nothing helpful about this in the Adobe AS3 coding conventions.

So why do we put the imports in the package and not the class that’s actually using them. The package is not using the imported classes is it? And why does it still work if I move the imports into the Class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:25:06+00:00Added an answer on May 15, 2026 at 11:25 am

    This is simply a convention that’s in use so there is one central place to view all of the imports. Let’s say we take your logic to the next extreme and place an import statement on the line just before every variable we declare (which compiles just fine by the way). We’d wind up needlessly duplicating import statements whether on purpose or by accident. Also, someone wanting to see what dependencies a given file has would have to scan the whole file rather than looking at just the top of the file. Your point of putting the imports within the class declaration isn’t as crazy, but you’d still wind up with the problem of imports scattered throughout a file if your file declares more than one class (as in the case of internally used classes, for example).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.