Hi Danny,

The idea of the import statement is to specify which class namespaces you
want to use. For example, there could be multiple packages that contain a
class named "Danny":
 com.kodicek.Danny
 com.day.lewis.Danny

If you wanted to use the first class, you'd need to write all of it every
time you wanted to instantiate it, like this:

myClass = new com.kodicek.Danny ()
myClone = new com.kodicek.Danny ()

But to make it easier, you can import it at the top of the containing class:

 import com.kodicek.Danny;

Having imported it, you let the containing class know which Danny you want
to be using, so then you can instantiate it without appending the full
package name each time:

myClass = new Danny()
myClone = new Danny()

You can also use:
  import com.kodicek.*;

And that would import all the classes in the specified package, saving you
the hassle of importing them one by one - but Flash will only compile the
class or classes you end up using in the script, keeping the swf size just
as small as if you'd used "import com.kodicek.Danny".

I hope that wasn't over-explaining: I know you're not exactly a newbie to
programming ;)

Karina



> -----Original Message-----
> From: Danny Kodicek [mailto:[EMAIL PROTECTED] 
> Sent: 19 March 2007 11:45
> To: [email protected]
> Subject: RE: [Flashcoders] Create an object by name
> 
>  > Hello Danny,
> >   This short snippet should return you the constructor:
> > 
> >     /** Returns the class constructor from a dotted path.
> >     * e.g. [EMAIL PROTECTED] var
> > cons:Function=getConstructorFromPath("com.pkg.fred.Bucket"); }
> >     */
> >     public static function
> > getConstructorFromPath(classPath:String):Function
> >     {
> >             var arr:Array=classPath.split(".");
> >             var obj:Object=_global;
> >             for(var i:Number=0;i<arr.length;i++)
> >             {
> >                     obj=obj[arr[i]];
> >             }
> >             return Function(obj);
> >     }
> > 
> > Then just do var obj:Object=new cons();
> 
> Thanks, Ian. So constructor functions are actually located in 
> _global space?
> That makes sense - is it always true, or do I need to ensure 
> it in some way?
> After all, if I do an import somewhere, that class is only 
> available in the scope of the import statement, not 
> everywhere in the movie (I think?).
> 
> Again, sorry to be pushing these questions so much - I just 
> find that once I understand what's going on 'behind the 
> scenes', I get much clearer about what my side of things is. 
> I'm still not entirely sure what import actually
> *does* :)
> 
> Danny
> 
> _______________________________________________
> [email protected]
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> 
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training 
> http://www.figleaf.com http://training.figleaf.com
> 

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to