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] 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:[EMAIL PROTECTED] 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
        


        


 

Reply via email to