Groups | Blog | Home
all groups > flash actionscript > march 2007 >

flash actionscript : Importing Class


numerical07
3/20/2007 10:19:26 PM
I was reading the tutorial on importing class's. This is what I read

Importing classes
To reference a class in another script, you must prefix the class name with
the class's package path. The combination of a class's name and its package
path is the class's fully qualified class name. If a class resides in a
top-level classpath directory--not in a subdirectory in the classpath
directory--then its fully qualified class name is its class name.

To specify package paths, use dot (.) notation to separate package directory
names. Package paths are hierarchical, where each dot represents a nested
directory. For example, suppose you create a class named Data that resides in a
com/xyzzycorporation/ package in your classpath. To create an instance of that
class, you could specify the fully qualified class name, as shown in the
following example:

var dataInstance = new com.xyzzycorporation.Data();

My Question is about com/xyzzycorporation/ . would the full class parth be
c:/com/xyzzycorporation/ . Why do they never state the drive letter when
teaching about directories.
SymTsb
3/20/2007 10:41:56 PM
Because there is no need. you don't need to reference the drive letter.

Here's the basic jist of what they are saying....

Single Class File...
If you create your own custom class and want to use it in your flash file,
save it into the same directory as the fla file and call the classes
constructor. By default flash will look inside the folder where the fla
resides in for the class files if it cannot find it inside the default
directory.

Multiple Class Files - 1 Project (often referred to as packages)
Use your qualified domain name but backwards.....
my domain is www.sd-dezign.com so if I was going to include a package of
utility class files in my document I would do the following
Create a folder in the same folder with my fla name it com and inside that a
folder called sddezign and inside that utils and all my as files would be in
there...the folder structure might look like this....

myfile.fla
com
[quoted text, click to view]

To call the constructor for each class, I have two options. The first which
is by far the easiest looks like this

In whatever frame you need to call that class constructor
include "com.sddezign.utils.*";
var myBox:Box = new Box();

The second method requires more typing and can get tedious

var myBox = new com.sddezign.utils.Box();

Hope this helps you a bit better.
numerical07
3/21/2007 3:58:41 PM
But what is this com directory. Is that a actual directory or is people just
using that for an example. Do i have to put my classes inside this com
directory and then put it in any sub directory within the com directory? What
if I wanted to save my class file in C:/mydocuments/myfiles/myfla/script.as .
would it be mydocuments.myfiles.myfla.script.as ???
kglad
3/21/2007 4:12:38 PM
com is an actual directory. the use of com/yourwebsitename is a convention to
prevent name collisions in case you download someone else's class files and
they happen to create a class with the same name as one of your classes or one
of your other downloaded classes. because your websitename.com is unique
com/websitename should be unique to everyone.

so, you don't have to follow convention. you could put your class file
anywhere on your computer or network and, as long as the path is specified,
flash will find it.
AddThis Social Bookmark Button