PDA

View Full Version : import statements



axiomflash
October 8th, 2007, 12:41 PM
Most of you probably agree that import statements are kind of a pain in the butt. Takes only a moment, but there is a lot of time that goes into adding the 30 lines at the top of your app that make everything work. I am starting to wonder if instead of importing each class I use, I should just import the whole flash framework off the bat. Why not?

import flash.display.*
import flash.events.*;
import flash.utils.*
import flash.xml.*

That's a lot shorter and less work. I imagine compile-time is longer but its not noticeable to me if so. So can someone really tell me, whats the benefit of not doing this?

onecommoncode
October 8th, 2007, 12:48 PM
I import only the ones that I need just because I want to learn them instead of importing them all at once.

Charleh
October 8th, 2007, 12:50 PM
Nothing - imports doesn't do anything except expose those namespaces to your code - so you might as well just do what you do! The only exception could be in namespaces with conflicting class names or namespaces which conflict with your own classes.

I'd save yourself the typing and just .* it!

senocular
October 8th, 2007, 01:08 PM
Specifying individual imports by name adds clarity. By that, and most importantly, it exposes the exact dependancies of that class. In using flash.display.* there's no way to tell if a MovieClip or Sprite is being used - or something completely different all together. It might not matter so much when dealing with native classes, but it can become helpful when dealing with other classes and knowing your dependancies becomes important.

Dazzer
October 8th, 2007, 01:25 PM
You could also do this if you want...


public class myClip extends flash.display.MovieClip{
}

I think.

soulwire
October 8th, 2007, 01:29 PM
If you decide to use an AS editor, like Flashdevelop or even Flex, it will add necessary imports for you as you reference classes. It will even do this for custom classes within your project. Easy!

I also agree with you guys though, it may be a pain in the arse (if you are using the Flash IDE and have to import manually), but it is good practice to be clear about what classes your project is using and worth doing.

senocular
October 8th, 2007, 01:31 PM
You could also do this if you want...


public class myClip extends flash.display.MovieClip{
}

I think.

That worked in AS2 without needing to use import, but AS3 now requires that import be used.

I think I liked it better the AS2 way

Dazzer
October 8th, 2007, 01:32 PM
Curses. Learning Java in uni is really killing me. And next year I start C...