4 Replies Latest reply on Nov 16, 2011 6:51 AM by jomor21

    Passing variable value and used it as component name?

    jomor21

      Hi,

       

      From a button a call to a function

      private function addContent(compon:String):void {

       

      Then I put in the code =

       

      var content:mycomponente = new components.mycomponete;

       

      Everything works fine.

       

       

      But I want to put the value of the variable loaded in the function (compon), as the name of the “component” .

       

       

      I tested  this code:

       

      var content:"${comp}"= new components.["${ compon}"];

       

      And it does not work. I've tested lots of combinations and nothing.

       

      Thanks

        • 1. Re: Passing variable value and used it as component name?
          Flex harUI Adobe Employee

          You can’t parameterize a compile-time type.  You can use a general type.

              var content:Object (or some other base class or interface for all types involved)

           

          You can convert a string to a type at runtime via getDefinitionByName, but you need a fully qualified class name.

          • 2. Re: Passing variable value and used it as component name?
            jomor21 Level 1

            Hi,

             

            I have tried what you tell me with all these variables:

             

            Var myClass: UIComponent, Object, Class, ComponentDescriptor

             

            and not get it to work

             

            I use a ViewStack with 6 canvas, activated by 6 buttons,  they call to a different external component type panel.

            If I can use as a reference parameter I can use a single function (with remove and add element) otherwise need to use 6 function.

             

            Flex harUI Thank you for your answer

             

            From Barcelona.

            • 3. Re: Passing variable value and used it as component name?
              Lisa_Florian

              Is this what you look for?

               

              viewStack.selectedChild = getChildByName(compon);

              • 4. Re: Passing variable value and used it as component name?
                jomor21 Level 1

                Nothing, not getting to work

                This is my code

                 

                   private function addContent(compon:String):void
                   {
                    if (compon == "tfg_compColeccion"){
                          var content:tfg_compColeccion = new components.tfg_compColeccion;
                          content.addEventListener("removeMe",onRemove,false,0,true);
                          var navContent:Canvas = new Canvas();
                          navContent.id = 'coleccion';
                          navContent.label = 'coleccion';
                          navContent.width = Number('100%');
                          navContent.height = Number('100%');
                          navContent.addElement(content);
                          myViewStack.addElement(navContent);
                          myViewStack.selectedChild = navContent;
                         }
                   }
                   private function onRemove(event:Event):void
                   {
                    var content:NewContent = event.currentTarget as NewContent;
                    content.removeEventListener("removeMe",onRemove,false);
                    myViewStack.removeChild(content.parent.parent.parent);

                   }


                thank you very much