Alternative to Import for Classes?

11 posts

Flag Post

I want to make a bitmap utility class, but I need the features that I normally use by writing “import flash.display.BitmapData;”. You can’t do this anywhere inside a Class file AFAIK, so how do you go about accomplishing this feat? Do I need to inherit or extend?

 
Flag Post

The simplest way is usually to extend the BitmapData class and add the needed functionality to the child class, but that is largely dependent upon what you specifically want to do.

 
Flag Post

How about if I wanted to use also the geometry api – if I extend the bitmapdata class then I don’t have access to the other stuff I would normally import – Guess I forgot to mention that in the first post, I would like to get the effect of importing more than once class… does that make any sense?

 
Flag Post

If you extend the Bitmapdata class you still have access to importing all the other classes just the same as you do in your previous classes. Thats the point of extending a class, so you can add functionality to an already existing base.

 
Flag Post

You can also write your import statements before the Class definition in the .as file at the top. You can also do multiple import statements there too — so you can import bitmap, geom, and point if you need them all in that class.

 
Flag Post

Oh ok I’ll try that, doing it above the class statement inside the same .as file – sounds contrary to the error message I recieved but hope it works!

 
Flag Post

Yes, thats how you always use the import statement. As I was saying, its the same in your subclasses as it is in your other classes.

 
Flag Post

I’m assuming that there’s no inheritance of the imported classes, or is there? In other words, if you have a class and a class which extends it, if you import geom, point, and bitmap (for instance) will you need to use the import statements again in the class which extends the class where the import statements were made.

 
Flag Post

Yes, you have to import again.

 
Flag Post

I suppose you have to Import again because the classes can be seperate from eachother?

 
Flag Post

You have to import on every individual frame and class file you want to use that code in. Such is just how it is as importing scopes the code to just the current script. Read here for more.