When you compile an application against, say, framework.swc, the MXML compiler "strips out" classes that the app doesn't need. But it does not strip out methods in the used classes even if those methods aren't called. The latter is what I would consider dead stripping. Classes are the "unit of linkage". A class is either in -- with all its methods -- or out. Rather than thinking of classes as being stripped out, you should think of them as being linked in. To determine the complete list of classes to be linked in, the MXML compiler starts with your application class and performs a dependency analysis. It adds the class corresponding to each MXML tag that you use. It adds the classes you use in your scripts in the following ways: extends/implements: class MyButton extends Button a type annotation: var foo:Button a new operation: new Button() a cast: Button(obj) a class reference: var c:Class = Button Then it adds the classes that these classes depend on, and the classes those classes depend on, etc. until the list stops growing and a "linkage closure" has been computed. There are some subtleties regarding how other special classes get linked in, such as those representing embedded graphics, styles, resources, etc., but you get the idea. The reason that even a very simple app written using the Flex framework is significantly larger than one written without it is that the Flex framework -- in order to be general purpose -- has a lot of capability in each class that a simple app may not need. For example, the UIComponent class supports measurement/layout, but you might be only using absolute positioning. It has dynamic CSS styles, but you might be content with the defaults appearance. It dispatches scads of events that you might not listen to. Dead-stripping of methods might someday make it possible to remove code like this that you app doesn't actually need. - Gordon
________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Troy Gilbert Sent: Wednesday, March 14, 2007 9:16 AM To: [email protected] Subject: Re: [flexcoders] Dynamic Instance of Class & Data Typing So, the Flex compiler *does* do dead stripping when linking? I didn't think it actually did this (which I assumed was the root cause for the size of my Flex apps vs. ActionScript apps ... usually a meg difference for bare bones stuff). I've never seen that mentioned in the docs and just assumed there was no dead-stripping... For example, if I created an app that used no UI elements (or minimal UI elements) then it should be pretty small, huh? Troy. On 3/13/07, Gordon Smith <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > wrote: A Flex Application is a SWF file that has only the ActionScript classes that the MXML compiler thinks your application needs. For example, iyour app just uses <mx:Application>, <mx:TextInput>, and <mx:Button>, the SWF isn't going to have the DataGrid or CreditCardValidator class linked into it. If all you do is call instantiateClass("MyComponent") the MXML compiler doesn't know it needs to link in the MyComponent class. But if you actually use MyComponent as a type somewhere, it will. For example, you could simply create a var with that type, as in import MyComponent; private static var foo:MyComponent; Simply importing the class is not enough; you must use it as a type somewhere. - Gordon ________________________________ From: [email protected] [mailto:[email protected] <http://yahoogroups.com> ] On Behalf Of Kevin Sent: Tuesday, March 13, 2007 4:34 PM To: [email protected] Subject: Re: [flexcoders] Dynamic Instance of Class & Data Typing what do you mean 'linked into your app'? the rest I understood. thanks! - Kevin On Mar 13, 2007, at 7:19 PM, Gordon Smith wrote: Yes, assuming that myFavoriteClass is actually linked into your app. You can use the getDefinitionByName() to look up a class by name, and the 'new' operator to create an instance of it. I think the code would be import flash.utils.getDefinitionByName; function instantiateClass(className:String):Object { var myClass:Class = Class(getDefinitionByName(className)); return new myClass(); } - Gordon ________________________________ From: [email protected] [ mailto:flexcoders <mailto:flexcoders> @yahoogroups.com] On Behalf Of Kevin Sent: Tuesday, March 13, 2007 2:44 PM To: [email protected] Subject: [flexcoders] Dynamic Instance of Class & Data Typing Is there a way to create new instances of a class dynamically at runtime: var someClass = "myFavoriteClass"; function instantiateClass(someClass){ var event: [someClass] = new [someClass] (); } Thanks, Kevin

