The import statement embeds, but so does this: var a:mx.controls.Button; import also allows you to use a shortcut as has been mentioned already.
>From the docs: "Lets you access classes without specifying their fully qualified names." .. "You must issue the import statement before you try to access the imported class without fully specifying its name. If you import a class but don't use it in your script, the class isn't exported as part of the SWF file. This means you can import large packages without being concerned about the size of the SWF file; the bytecode associated with a class is included in a SWF file only if that class is actually used." If you import but don't use it it's not included ... however, in practice you can definitely see that the SWF file size has changed. I took a blank FLA and published for a SWF size of 43 bytes. I then used this code: import mx.controls.Button; import mx.controls.List; import mx.controls.Tree; import mx.controls.DataGrid; import mx.containers.Accordion; File size: 42.5 KB I then used this code: var b:mx.controls.Button; var l:mx.controls.List; var t:mx.controls.Tree; var d:mx.controls.DataGrid; var a:mx.containers.Accordion; FileSize: 48.3 KB I then used this code: import mx.controls.Button; import mx.controls.List; import mx.controls.Tree; import mx.controls.DataGrid; import mx.containers.Accordion; var b:Button; var l:List; var t:Tree; var d:DataGrid; var a:Accordion; FileSize: 48.3 KB So the classes seem to be included in the SWF with just the import statements. Of course there is no difference if you import and use them compared to using them with explicit reference to the classes. Now the docs say that import by itself doesn't include the classes, but I used this code: import mx.controls.Button; import mx.controls.List; import mx.controls.Tree; import mx.controls.DataGrid; import mx.containers.Accordion; trace(_global['mx']['controls']['Button']); The output panel displays [type Function] telling me that the class was indeed included. The compiler doesn't understand the [] notation as a reference to the class during compile-time, so I don't think that's why it worked. I think the classes are indeed included. However, someone could prove me wrong. Incidentally, the file size was 42.5 KB ... so, trim the fat and use [] notation! Derek Vadneau ----- Original Message ----- From: "Merrill, Jason" <[EMAIL PROTECTED]> To: "Flashcoders mailing list" <flashcoders@chattyfig.figleaf.com> Sent: Thursday, May 25, 2006 1:24 PM Subject: RE: [Flashcoders] OOP 101: Is import really necessary? >>The 'import' statement doesn't actually embed a class into the .swf. >>All it does is tell the compiler that when you type (for example) >>MyClass, you are actually referring to com.fred.MyClass. Err...that has not been my understanding at all. If that is the case, then why do you NOT need to include your class files on the server with the .swf? Since reality is you don't, all that code has to be in the swf upon compiling, otherwise, the .swf wouldn't know what to do with Myvar:MyCoolClass = new MyCoolClass(); If it's not included with the .swf, how would the .swf know what MyCoolClass is otherwise? Jason Merrill Bank of America Learning Technology Solutions _______________________________________________ Flashcoders@chattyfig.figleaf.com 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