Dynamic creation of classes

hi there
i was wondering if it was possible to create an instance of a
class (AS 2.0) at runtime, given just a string value for the class
name
eg, my first attempt was something like
var class_str:String = "MyClass1";
var inst
bject = new eval(class_str)();
now, "eval(class_str)" returns an object of type "function",
ie the function reference to the class constructor, and so all i
get is a new "function object"
any clues, or am i p***ing in the wind?
tia
bhu

I'm afraid "eval()" can't be used this way:
LiveDocs

Similar Messages

  • Dynamic creation of class at runtime

    I need to be able to dynamically create an instance of a
    class that isn't known until runtime - actually based on the
    filename
    so in my fla:
    var className:String="Test"; /* code to get a class name
    derived from the filename */
    var obj = new [className]();
    trace(obj);
    the code above only works if i put the literal directly in [
    like so:
    var obj = new ["Test"]();
    is there a way to do this???
    Any help much appreciated
    cheers Steve

    This might help you out:
    http://dynamicflash.com/2005/03/class-finder/
    "steveanson" <[email protected]> wrote in
    message
    news:e3fcnv$6c7$[email protected]..
    > I need to be able to dynamically create an instance of a
    class that isn't
    known
    > until runtime - actually based on the filename
    >
    > so in my fla:
    > var className:String="Test"; /* code to get a class name
    derived from
    the
    > filename */
    > var obj = new ();
    > trace(obj);
    >
    > the code above only works if i put the literal directly
    in
    > like so:
    > var obj = new ();
    >
    > is there a way to do this???
    > Any help much appreciated
    > cheers Steve
    >
    >
    >

  • Help with dynamic creation of class object names

    Hi all
    Wonder if you can help. I have a class player.java. I want to be able to create objects from this class depending on a int counter variable.
    So, for example,
    int counter = 1;
    Player p+counter = new Player ("Sam","Smith");the counter increments by 1 each time the method this sits within is called. The syntax for Player name creation is incorrect. What I am looking to create is Player p1, Player p2, Player p3.... depending on value of i.
    Basically I think this is just a question of syntax, but I can't quite get there.
    Please help if you can.
    Thanks.
    Sam

    here is the method:
    //add member
      public void addMember() {
        String output,firstName,secondName,address1,address2,phoneNumberAsString;
        long phoneNumber;
        boolean isMember=true;
        this.memberCounter++;
        Player temp;
        //create HashMap
        HashMap memberList = new HashMap();
        output="Squash Court Booking System \n";
        output=output+"Enter Details \n\n";
        firstName=askUser("Enter First Name: ");
        secondName=askUser("Enter Second Name: ");
        address1=askUser("Enter Street Name and Number: ");
        address2=askUser("Enter Town: ");
        phoneNumberAsString=askUser("Enter Phone Number: ");
        phoneNumber=Long.parseLong(phoneNumberAsString);
        Player p = new Player(firstName,secondName,address1,address2,phoneNumber,isMember);
        //place member into HashMap
        memberList.put(new Integer(memberCounter),p);
        //JOptionPane.showMessageDialog(null,"Membercounter="+memberCounter,"Test",JOptionPane.INFORMATION_MESSAGE);
        //create iterator
        Iterator members = memberList.values().iterator();
        //create output
        output="";
        while(members.hasNext()) {
          temp = (Player)members.next();
          output=output + temp.getFirstName() + " ";
          output=output + temp.getSecondName() + "\n";
          output=output + temp.getAddress1() + "\n";
          output=output + temp.getAddress2() + "\n";
          output= output + temp.getPhoneNumber() + "\n";
          output= output + temp.getIsMember();
        //display message
        JOptionPane.showMessageDialog(null,output,"Member Listings",JOptionPane.INFORMATION_MESSAGE);
      }//end addMemberOn running this, no matter how many details are input, the HashMap only gives me the first one back....
    Any ideas?
    Sam

  • Dynamic creation of class objects?

    I have a requirement where in at runtime I would know the class name, method name, properties, interface..and coding lines to be put into a method?
    Can anyone suggest a way to create the consumable central class object with these details, activate it and without any manual intervention create this object in backend?

    From other thread...use SEO* package

  • Dynamic Creation of Class Name

    I just want to create the class name on the fly.
    Look the example below.
    String className = "gui.Header";
    className header = new className;
    Let's assume that there is a Header class somewhere.
    Is this possible? or is there a way to do this?

    From what i understand, u wish to create an instance of a class whose name is known to you at runtime - correct me if i'm wrong - i'll answer based on my assumption. You can basically do that using Reflection in Java. I'm pasting sample code which shows how you do this:
    The following sample program creates an instance of the Rectangle class using the no-argument constructor by calling the newInstance method:
    import java.lang.reflect.*;
    import java.awt.*;
    class SampleNoArg {
    public static void main(String[] args) {
    Rectangle r = (Rectangle) createObject("java.awt.Rectangle");
    System.out.println(r.toString());
    static Object createObject(String className) {
    Object object = null;
    try {
    Class classDefinition = Class.forName(className);
    object = classDefinition.newInstance();
    } catch (InstantiationException e) {
    System.out.println(e);
    } catch (IllegalAccessException e) {
    System.out.println(e);
    } catch (ClassNotFoundException e) {
    System.out.println(e);
    return object;
    Hope the above helps.
    John Morrison

  • Dynamic creation of class and calling methods

    I've got and interface called Transformation and then two implementations called TxA and TxB, where TxA and TxB have their own attribtues and setter and getters for these attributes.
    The question is, I need to create instances of TxA and TxB and called the setter and getters where I at runtime I only know the attribute to set, how can I create and instance and call the right getters and setters methods?
    Thanks in advance

    Smart money says your design sucks and needs to be rethought entirely. Can we get specifics?
    Drake

  • Dynamic creation of TabStrip

    Hi,
    I want to create a tabstrip dynamically.The tabstrip should have 3 tabs, and in each of the tabs i want to put some UI elements like a label, input field, dropdown, tables.........etc.
    Im able to create the tabstrip and add tabs to it dynamically.
    I've even created the UI elements which i wanted to put in the tabs.............But im not able to proceed as i dont know how to add the UI elements to the tabs.......
    Can anyone tell me how to add UI elements to a tab in a tabstrip?
    Regards,
    Padmalatha.K
    Points will be rewarded.

    Hi,
    Following code will help you to understand the dynamic creation and adding them
    //Tabstrip
           IWDTabStrip tabStrip = view.createElement(IWDTabStrip.class);
           //Tab
           IWDTab tab = view.createElement(IWDTab.class);
           //Input Field
           IWDInputField inputField = view.createElement(IWDInputField.class);
           //Adding inputfield to tab
           tab.setContent(inputField);
           //Adding tab to tabstrip
           tabStrip.addTab(tab);
    //Finally add this tabstip to either your root container or some other container.
    Regards
    Ayyapparaj

  • Dynamic creation of business graphics.

    Hi,
    i have a piece of code which dynamically create a business graphics. If i use the same node data and create BG in statically.. i am able to view the graph. In case of dynamic creation , i am getting graphical rendering error. Have i missed something here..
    The piece of code i had used is..
         IWDBusinessGraphics bg = (IWDBusinessGraphics)view.createElement(IWDBusinessGraphics.class,null);
              IWDCategory c = (IWDCategory)view.createElement(IWDCategory.class,null);
         //     c.setDescription("tableutility");      
              c.bindDescription(wdContext.getNodeInfo().getAttribute(IPrivateSDNUtilityView.IContextElement.TEST));                                                                               
    bg.setCategory(c);
              bg.setDimension(WDBusinessGraphicsDimension.PSEUDO_THREE);
              IWDSimpleSeries ss = (IWDSimpleSeries)view.createElement(IWDSimpleSeries.class,null);
              ss.bindValue(wdContext.nodeDepartments().getNodeInfo().getAttribute(IPrivateSDNUtilityView.IDepartmentsElement.NO_OF_PEOPLE));
              ss.setLabel("Simple Series");
              ss.setLabel("No of People");
              bg.addSeries(ss);
              bg.setChartType(WDBusinessGraphicsType.COLUMNS);
              bg.bindSeriesSource(wdContext.nodeDepartments().getNodeInfo());
              bg.setIgsUrl("http://<hostname>:40080");
    Please help.
    Regards
    Bharathwaj

    Please got through following link
    <a href="/people/sap.user72/blog/2006/05/04/enhancing-tables-in-webdynpro-java-150-custom-built-table-utilities:///people/sap.user72/blog/2006/05/04/enhancing-tables-in-webdynpro-java-150-custom-built-table-utilities

  • Dynamic Creation of Buttons and Actions HELP

    Hi there,
    I have got a problem (or maybe even two) with the dynamic Creation of buttons. The code below creates the buttons.
    My main problem is, that the parameter created for the button's action isn't propagated to the assigned event handler. I get a null, though the name of the parameter in the event handler and the name of the parameter added to the action are the same.
    Could it also be that I'm always using the same action? I.e. does wdThis.wdGetAddElementAction() always return the same action instance? If yes, how can I create individual actions for each button?
    Any help is appreciated!
    Cheers,
    Heiko
    "    for(int i=rootContainer.getChildren().length; i<wdContext.nodeFeature().size();i++)
                   IPrivateVCT_Feature.IFeatureElement featureElement = wdContext.nodeFeature().getFeatureElementAt(i);
                   IWDTray featureTray = (IWDTray) view.createElement(IWDTray.class, featureElement.getName());
                   IWDCaption header = (IWDCaption) view.createElement(IWDCaption.class, featureElement.getName()+"_Header");
                   header.setText(featureElement.getName());
                   featureTray.setHeader(header);
                   featureTray.setExpanded(false);
                   rootContainer.addChild(featureTray);
                   IWDButton button = (IWDButton) view.createElement(IWDButton.class, featureElement.getName()+"_Button_AddElement");
                   IWDAction actionAddElement = wdThis.wdGetAddElementAction();
                   actionAddElement.getActionParameters().addParameter("featureIndex", new Integer(i).toString());
                   button.setOnAction(actionAddElement);
                   button.setText("Add Element");
                   featureTray.addChild(button);

    Hi Heiko,
    You have done everything correctly....except for 1 line
    in the code...
    Replace the following line in your code:
    actionAddElement.getActionParameters().addParameter("featureIndex", new Integer(i).toString());
    Replace the above line with this code:
    button.mappingOfOnAction().addParameter("featureIndex",i);
    Actually in your code, you are not associating the parameter with the button...
    Note that addParameter(...) comes with two signatures: addParameter(String param, String value) and addParameter(String param, int value). You can use any of them based on yuor need.
    Hope it helps,
    Thanks and Regards,
    Vishnu Prasad Hegde

  • Dynamic creation of ComponentUsage

    Hi people,
    I want to reuse a view (ViewA) in different views (ViewB, ViewC, ViewD).ViewA has a quite complex logic, so it is necessary to outsource this view.  Not only the logic, but also the count of UIElements and contextelements is quite large, for this I don't want to implement this part redundant in the views A, C and D.
    I have to use ViewA in a table in  the TablePopin UIElement. Every line of the table should have its own instance of ViewA. Is that possible?
    My idea is it, to put the view in an own component. For every tableline I need an instance of the componentUsage. My problem is now, that I'm not able to create at runtime a ComponentUsage and at designtime I don't know how many instances I need. Is it possible in webdynpro to create dynamic instances of ComponentUsage?
    If you know an other way, that prevents me from implementing the view and its logic more times, please tell me!
    Thanks in  advance,
    Thomas Morandell

    Hi Thomas,
    just for clarification. Principally it is possible in Web Dynpro to dynamically create new component usages of the same type like an existing, statically declared one. This means after having defined a component usage of type ISomeComp (component interface definition) you can dynamically create new component usages which all point to the same component interface definition ISomeComp:
    wdThis.wdGetISomeCompUsage().createComponentUsageOfSameType();
    But this dynamic creation approach implies, that you must also embed the component interface view of this component usage to the view composition dynamically; and this is (unfortunately) quite cumbersome and complicated based on the existing Web Dynpro Java API (it is not yet optimized for a simple dynamic view composition modification.
    Additionally, like Valery pointed out, the dynamic creation of new component usages is not compatible with table popins.
    Regards, Bertram

  • Dynamic Creation of UI in adobe forms??

    Hi Experts,
    I need to create a dynamic interactive form and dynamic UI elements in the interactive form.
    As per my requirement I need to display a pdf and I will be getting values from the RFC's. I need to show the form segments and the UI elements only when there's a data from the RFC else not. I am unable to understand whether this requirement needs generation of the UI elements dynamically or I can do it statically as well.
    The form thus generated will be having data from the RFC which based on the data quantity may exceed to n number of pages.
    In case it needs dynamic creation can you suggest me please how to achive it in interactive forms?
    Helpful answers will be appreciated.
    Warm Regards,
    Gaurav

    Hi,
    subForm1:-
    Flow content
    Allow page breaks
    Place: following previous-----> This means when you are repeating the subform the previous one should be followed.
    Say you have a table and have 3 columns in it.
    After 1st column is completed, the next column should come with 1st comun
    After: Continue filling parent--->Continously fill the data with the parent element
    Repeat sub form min count is 1 : Minimum of 1 line item will be printed
    Height: Expand to fit is true.: If the field height is increased it automatically expands.
    For help in Adobe Press F1 or Goto Help--> Adobe Designer Help in Adobe Designer
    After installing Adobe Designer, goto the specific folder
    C:\Program Files\Adobe\Designer 8.0\EN you can get sample documents.
    For help press F1 after opening designer.
    Sub Form1: Content--> Flowed, Flow direction --> Top to bottom
                       Binding --> Check the checkbox Repeat Subform for each data item
    Subform 2: Content --> Positioned, No pagination No binding settings changes needed.
    Hey i forgot to mention the Header Subform where you create all these subforms should be flowed.
    Try it once like this and lte us know
    Edited by: Sankar Narayana on Oct 3, 2008 5:06 PM

  • Dynamic creation of date in selection variant

    Hi All,
    I have a Z program for updating a field in BOM item. One of the input field in the report is "Valid From Date". Actually the current date is automatically fetched through a function module and it is defaulted in that field. 
    Our client is using selection variant for ease of use. The problem here is old date in the selection variant  is replacing the current date. I want current date to be created automatically during insertion of variant also. How can i solve this problem. Is there any selection variable inside the variant for dynamic creation of Date?
    Thanks
    Sankar

    As I know there is no setting for this. For any std or Z report variant function with L should act same way...anyway you discuss with your ADABer.
    See the help for variables
    Selection Variables                                                                               
    The following three types of selection variables are currently          
        supported:                                                                               
    o   Table variables from TVARV                                          
            You should use these variables if you want to store static          
            information. TVARV variables are proposed by default.                                                                               
    o   Dynamic date calculations:                                          
            To use these variables, the corresponding selection field must have 
            type 'D' (date). If the system has to convert from type T to type D 
            when you select the selection variables, the VARIABLE NAME field is 
            no longer ready for input. Instead, you can only set values using   
            the input help.                                                     
            The system currently supports the following dynamic date            
            calculations:                                                       
            Today's date                                                        
           From beginning of the month to today                               
           Today's date +/- x days                                            
           First quarter ????                                                 
           Second quarter ????                                                
           Third quarter ????                                                 
           Fourth quarter ????                                                
           Today's date - xxx, today's date + yyy                             
           Previous month                                                                               
    o   User-specific variables                                            
           Prerequisite: The selection field must have been defined in the    
           program using the MEMORY ID pid addition. User-specific values,    
           which can be created either from the selection screen or from the  
           user maintenance transaction, are placed in the corresponding      
           selection fields when the user runs the program.                                                                               
    The SELECTION OPTIONS button is only supported for date variables that 
       fill select-options fields with single values.                         
    i.e means we can do that with D also.

  • Error editing task sequence: Failed to load dynamic properties for class "SMS_TaskSequence_ApplyWindowsSettingsAction" From XML into WMI

    I've started getting an intermittent error editing my Windows 7 OSD task sequence.  Sometimes I can open the TS to edit, but when I try to apply changes I get the error.  Other times I get the error when trying to open the TS.  If I try again
    right away, I still get the error, but if I wait a few minutes and try again sometimes it will open the TS. 
    The error reads:
    ConfigMgr Error Object:instance of SMS_Extended Status{Description = "Failed to load dynamic properties for class \"SMS_TaskSequence_ApplyWindowsSettingsAction\" from XML into WMI";Error Code = 2147943746;File = "e:\\qfe\\nts\\sms\\siteserver\\sdk_provider\\smsprov\\ssptspackage.cpp";Line = 3454;Operation = "ExecMethod";ParameterInfo = "SMS_TaskSequencePackage";ProviderName = "WinMgmt";StatusCode = 2147749889;}
    Coinciding with this error, I show the following entries in the TaskSequenceProvider.log file: 
    [PID: 7608] Invoking method SMS_TaskSequence.LoadFromXml
    TaskSequenceProvider
    Failed to protect memory buffer, hr=0x80070542
    TaskSequenceProvider
    Failed to load dynamic properties for class "SMS_TaskSequence_ApplyWindowsSettingsAction" from XML into WMI 0x80070542 (2147943746)
    TaskSequenceProvider
    Failed to load node Apply Windows Settings from XML into WMI 0x80070542 (2147943746)
    TaskSequenceProvider
    Failed to load children steps for node "PostInstall" from XML 0x80070542 (2147943746)
    TaskSequenceProvider
    Failed to load children steps for node "Execute Task Sequence" from XML 0x80070542 (2147943746)
    TaskSequenceProvider
    Failed to load children steps for node "" from XML 0x80070542 (2147943746)
    TaskSequenceProvider
    Failed to load XML for the task sequence into WMI 0x80070542 (2147943746)
    TaskSequenceProvider
    [PID: 7608] Done with method SMS_TaskSequence.LoadFromXml
    TaskSequenceProvider
    Setting status complete:  status code = 0x80070542; Failed to load dynamic properties for class "SMS_TaskSequence_ApplyWindowsSettingsAction" from XML into WMI
    TaskSequenceProvider
    I exported the task sequence and checked in "object.xml" for the "ApplyWindowsSettingsAction", to see if there was something odd in the xml, but I don't find anything that jumps out as being wrong.  Here's the section of XML for
    that step.  I've removed identifying info, and replaced it with a generic term in bold.
    <step type="SMS_TaskSequence_ApplyWindowsSettingsAction" name="Apply Windows Settings" description="" runIn="WinPE" successCodeList="0" runFromNet="false"><action>osdwinsettings.exe /config</action><defaultVarList><variable name="OSDLocalAdminPassword" property="AdminPassword"></variable><variable name="OSDComputerName" property="ComputerName">%_SMSTSMachineName%</variable><variable name="OSDProductKey" property="ProductKey"></variable><variable name="OSDRandomAdminPassword" property="RandomAdminPassword">false</variable><variable name="OSDRegisteredOrgName" property="RegisteredOrgName">COMPANY NAME</variable><variable name="OSDRegisteredUserName" property="RegisteredUserName">COMPANY NAME</variable><variable name="OSDServerLicenseConnectionLimit" property="ServerLicenseConnectionLimit">5</variable><variable name="OSDTimeZone" property="TimeZone">Central Standard Time</variable></defaultVarList></step><step type="SMS_TaskSequence_ApplyNetworkSettingsAction" name="Apply Network Settings" description="" runIn="WinPEandFullOS" successCodeList="0" runFromNet="false"><action>osdnetsettings.exe configure</action><defaultVarList><variable name="OSDDomainName" property="DomainName">DOMAIN.COM</variable><variable name="OSDJoinPassword" property="DomainPassword"></variable><variable name="OSDJoinAccount" property="DomainUsername">DOMAIN ACCOUNT</variable><variable name="OSDEnableTCPIPFiltering" property="EnableTCPIPFiltering" hidden="true">false</variable><variable name="OSDNetworkJoinType" property="NetworkJoinType">0</variable><variable name="OSDAdapterCount" property="NumAdapters" hidden="true">0</variable></defaultVarList></step>
    Is there any other log I should check for a clue on this issue?  What could be causing this error?

    Thanks for sharing that!  I tend to save contacting MS support until after I've exhausted other options.  I'm always afraid that I'll spend the $500 to open a case and then it turns out to be something simple that I would have found if I had just
    kept working on it myself a little longer.
    It looks like that link is for an update released in February as KB3023562.  I downloaded and installed it. I'll try opening/editing/saving the task sequence a few times today to see if the issue is resolved.  
    After I had already installed it, I thought to look up that update in configmgr.  The update is listed as superseded by 2 other updates.  The newest of those is KB3046049, which just installed last night with the other March patches, so it's possible
    that I didn't need to install KB3023562 after all.  

  • Dynamically loading a class that is part of a larger loaded package

    I am dynamically loading a class that is part of a large package, much of which is loaded at startup. The code directly references protected variables in the parts of the package that is loaded by the default class loader. Attempting to access these protected variables gives an access error when the class is dynamically loaded that doesnt occur when the class is loaded at startup.
    Is there a way to make this work?

    To answer my own question -- no
    A reference from http://access1.sun.com/techarticles/DR-article.html says:
    The use of Dynamic Class Reloading can introduce problems when classes that are being dynamically reloaded make calls to non-public methods of helper classes that are in the same package. Such calls are likely to cause a java.lang.IllegalAccesserror to be thrown. This is because a class that is dynamically reloaded is loaded by a different classloader than the one used to load the helper classes. Classes that appear to be in the same package are effectively in different packages when loaded by different classloaders. If class com.myapp.MyServlet is loaded by one classloader and an instance of it tries to call a non-public method of an instance of class com.myapp.Helper loaded by a different classloader, the call will fail because the two classes are in different packages.
    So not being able to access non-private variables in this scenario is the way it works.

  • Dynamic Java bean classes for XSD using JAVA (not any external batch or sh)

    Hi,
    How can we generate dynamic Java bean classes for XSD (dynamically support All XSD at runtime)?
    Note: - Through java code via only needs to generate this process. (Not using any xjc.bat or xjc.sh from JAXB).
    Thanks

    Muthu wrote:
    How can we generate dynamic Java bean classes for XSD (dynamically support All XSD at runtime)?
    Pretty sure you can't. Probably can do a lot of them with years of work.
    And can probably can do a resonable subset suitable for the business at hand with only a moderate effort.
    Note: - Through java code via only needs to generate this process. (Not using any xjc.bat or xjc.sh from JAXB).The Sun jdk, not jre, comes with the java compiler as part of it. You can create in memory class (I believe in memory) based on java code you create.
    I believe BCEL alllows the same thing (in memory) but you start with byte codes.
    You could just create a dynamic meta data solution as well, via maps and generic methods. Not as fast though.

Maybe you are looking for