6 Replies Latest reply on Jul 10, 2007 10:16 AM by Newsgroup_User

    Import statement *not* required?

    midimidi Level 1
      Can someone explain this to me? I was following along a simple AS3 example (in the design video workshop) where a "Power Button" has some MouseEven CLICK event handling applied to it with a trace statement as the resulting handled function. Really simple basic example. The import statement is import flash.events.MouseEvent.

      How come removing the import statement does not produce an error?

      Reference:
      import flash.events.MouseEvent;
      myButton.addEventListener(MouseEvent.CLICK, myButtonClicked);
      function myButtonClicked(event:MouseEvent):void {
      trace('do Something');
      }
        • 1. Re: Import statement *not* required?
          SymTsb Level 2
          is this on the main movie's timeline or in a separate AS file? If it is in a separate AS file, is that AS file being imported into the main movie's timeline?
          • 2. Re: Import statement *not* required?
            kglad Adobe Community Professional & MVP
            because that code is on the main timeline of a swf and your publish settings give flash access to all the class files.
            • 3. Re: Import statement *not* required?
              Level 7

              It did strike me *** odd though, an imported .as file uses the same
              publish settings as code on the timeline. So why treat them differently?

              Feels kinda daft to explicitly import stuff if you place the code in the
              timeline just because you should get accustomed to it.

              Oh well, probably reasons enough...

              kglad wrote:
              > because that code is on the main timeline of a swf and your publish settings give flash access to all the class files.

              --
              ----------
              Manno Bult
              http://www.aloft.nl
              • 4. Import statement *not* required?
                midimidi Level 1
                Thanks guys.

                So to be clear...if the AS is on the main timeline, import statements are not needed, and if the AS is external and imported, import statements are needed - correct?

                And if so, are there any exceptions to that, or does that go for all AS3 classes?
                • 5. Re: Import statement *not* required?
                  Level 7
                  midimidi,

                  > So to be clear...if the AS is on the main timeline, import statements
                  > are not needed, and if the AS is external and imported, import
                  > statements are needed.

                  That's a general rule of thumb, but not 100% applicable.

                  > Are there any other exceptions to that, or does that go for all AS3
                  > classes?

                  There are exceptions, and the easiest way to find them is to leave out
                  your import statements and plug away ... sooner or later, you'll get a
                  compiler error, and then you'll know. :)

                  >> It did strike me *** odd though, an imported .as file uses the same
                  >> publish settings as code on the timeline. So why treat them differently?

                  FLA files have publish settings, but AS files don't. They're just text
                  files. I hear what you're saying ... they end up getting compiled along
                  with / into the some FLA anyway -- and that FLA does have classpaths
                  listed -- but those same AS files might be compiled in Flex Builder 2 or
                  some 3rd party compiler. It would probably make good sense to require the
                  import statement for inline FLA code, but not everyone is a hardcore
                  programmer, and Adobe knows it. Nothing is *hurt* by using import in FLAs,
                  but for folks who just want to do light programming, the convenience of not
                  having to use it is nice.


                  David Stiller
                  Adobe Community Expert
                  Dev blog, http://www.quip.net/blog/
                  "Luck is the residue of good design."


                  • 6. Re: Import statement *not* required?
                    Level 7


                    David Stiller wrote:
                    > FLA files have publish settings, but AS files don't. They're just text
                    > files. I hear what you're saying ... they end up getting compiled along
                    > with / into the some FLA anyway -- and that FLA does have classpaths
                    > listed -- but those same AS files might be compiled in Flex Builder 2 or
                    > some 3rd party compiler. It would probably make good sense to require the
                    > import statement for inline FLA code, but not everyone is a hardcore
                    > programmer, and Adobe knows it. Nothing is *hurt* by using import in FLAs,
                    > but for folks who just want to do light programming, the convenience of not
                    > having to use it is nice.
                    >

                    It's probably just when I was trying to get acquainted with the new
                    classes the first test seemed sort of in vain because I might as wel
                    have imported totally obsolete classes. Never really found any
                    documentation too about this (or did I just not look good enough).

                    I know it must be a relief to not have to find the proper classes. I
                    consider myself an OK scripter, but it takes some time to find the
                    proper classes and code from scratch...

                    All for the better I suppose :)

                    --
                    ----------
                    Manno Bult
                    http://www.aloft.nl