8 Replies Latest reply on Sep 29, 2006 9:32 AM by TimSymons

    Create Component Instance Dynamically

    S4Potential Level 1
      I want to create Flash built-in components (buttons, combo lists, etc...) without having them physically existing in the library. Is it possible to register the one I want to use with Actionscript only?
        • 1. Re: Create Component Instance Dynamically
          Peter Lorent Level 2
          No. The components you want to use need to be in a the library (you can possible use a shared library).
          • 2. Re: Create Component Instance Dynamically
            S4Potential Level 1
            My understanding of shared libray is:
            1. Only regular symbols can be shared. I tried with a component and didn't have any success.
            2. The object still needs to be in both library. The source and the destination libraties so if you update the source, the destination gets the update at run time. No need to recompile.

            What about the registerClass() method. Can it be used for components and if yes, how?
            • 3. Re: Create Component Instance Dynamically
              Peter Lorent Level 2
              1. Did you try that with the combobox? I know that the combobox needs to be in both libs but it doesn't work for other components too? Well, never tried that.
              registerClass() is AS1. No use in AS2. AS2 uses the linkage identifier in the lib.
              • 4. Re: Create Component Instance Dynamically
                S4Potential Level 1
                I tried with a button without success and when you go in the linkage dialogue box for a component the "import" option is disabled but if you set the source component linkage to export and drag it to the destination library the import is then automatically checked but it still doesn't work.

                As for the registerClass() method, yes, I knew it is and AS1 method. The AS2 linkage identifier is no use if what your looking for is a 100% dynamic component creation.

                I thought importing the class would work (as in import mx.controls.Buttons) but without the corresponding component in the library it doesn't let you create a component using createClassObject()

                This is a bummer :o(

                Thankx for your comments though.
                • 5. Re: Create Component Instance Dynamically
                  Glazer Level 1
                  couldn't you use an import statement to include the actual .as file which relates to the specific component?
                  • 6. Re: Create Component Instance Dynamically
                    Peter Lorent Level 2
                    >>importing the class
                    The import statement doesn't really import anything. It just enables you to not have to type the fully qualified path to the class.
                    >>a 100% dynamic component creation
                    Nope, components need to be in the lib. At least, I never encountered a 100% dynamic solution.
                    • 7. Re: Create Component Instance Dynamically
                      Glazer Level 1
                      yip LuigiL you're right, sorry guys didn't understand the question fully.
                      • 8. Re: Create Component Instance Dynamically
                        TimSymons Level 1
                        Yep, they have to be in the Library. Try the following in a new Flash document. Just open one up (with nothing in the library) and place the fillowing script:

                        this.createClassObject(mx.controls.CheckBox, "testAge_ch", 1, {label:'Age Range', selected:true});
                        this.createClassObject(mx.controls.TextInput, "minimumAge_ti", 2, {restrict:[0-9], text:18, maxChars:2});
                        minimumAge_ti.move(20, 30);
                        this.createClassObject(mx.controls.TextInput, "maximumAge_ti", 3, {restrict:[0-9], text:55, maxChars:2});
                        maximumAge_ti.move(20, 60);
                        stop();

                        When you test it nothing happens. Now, add the CheckBox component and TextInput component to the library. When you test it now, you should see 1 checkbox and 2 input fields.

                        Tim