2 Replies Latest reply on Feb 23, 2010 3:59 AM by yehuda1233456

    innerHTML equivalent

    yehuda1233456

      hi everyone i need your help (sorry for my english)

      lets say i have this element :

       

      <mx:VBox id="test" click="insertMxml(event)">

       

      </mx:VBox>

       

      And I want to inset mxml inside it dynamically  when the user clicks the element or do something else in the page.

      in javascript i will simply write:

       

      <script>

          function insertHTML(){

                test.innerHTML = "<myHTML stuff>"

           }

      </script>

       

       

      <mx:script>

           public function insertHTML(event:MouseEvent):void{

                what should i do in flex...? 

            } 

      <mx:/script>

       

       

      thank you very much head!

        • 1. Re: innerHTML equivalent
          archemedia Level 4

          You cannot add 'mxml' at runtime, but since mxml is in fact pure AS3, you can. Use AddChild method to do this.

           

          <mx:VBox id="test" click="insertMxml(event)">

           

          </mx:VBox>

           

          ...

           

          private function insertMxml(evt:Event):void

          {

               var myComp:MyCustomComp = new MyCustomComp();

               evt.target.addChild(myComp);

          }

           

          You can make this as simple or as complex as you want. The simplest way is to make a custom component and add an instance of it to a visual container (in this case a VBox).

           

          You can remove childs using methods like removeChildAt, removeAllChildren...

           

          Dany

          • 2. Re: innerHTML equivalent
            yehuda1233456 Level 1

            thank you!

             

            I really think they should add function that enables adding mxml in run time like DOM, it's very convenient