4 Replies Latest reply on Jan 13, 2009 12:58 AM by atta707

    Create controls through actionscript

    khaldoon.masud
      Hi,
      i know that we can create dynamic controls through actionscript by creating their object and setting appropriate properties, but i want to create objects as javascript do such as: doucment.write("<input type='text' />");
      another example(php): echo "<input type='text' />";
      Can i create controls in actionscript as i created above...? Do flex has this feature?
      I hope you understand what i want to do.
        • 1. Re: Create controls through actionscript
          Level 7

          "khaldoon.masud" <webforumsuser@macromedia.com> wrote in message
          news:gkfe4a$9h8$1@forums.macromedia.com...
          > Hi,
          > i know that we can create dynamic controls through actionscript by
          > creating
          > their object and setting appropriate properties, but i want to create
          > objects
          > as javascript do such as: doucment.write("<input type='text' />");
          > another example(php): echo "<input type='text' />";
          > Can i create controls in actionscript as i created above...? Do flex has
          > this
          > feature?
          > I hope you understand what i want to do.

          Look in the Help for "addChild".

          HTH;

          Amy


          • 2. Re: Create controls through actionscript
            Gregory Lafrance Level 6
            I don't think you can create controls as in JavaScript, if I understand you correctly.

            As Amy suggested, you need to create the control object, modify its properties, and then use addChild() to add the object to the display list.
            • 3. Re: Create controls through actionscript
              khaldoon.masud Level 1
              thanks for your replies, but i think you didn't get my point. I know that i can create control through actionscript.for example:
              btn1:Button =new Button();
              btn1.id="btn1";
              btn1.label="Button1";
              btn1.move(50,50);
              addchild(btn1);

              it is 100% ok, but i want to create it as:
              addchild("<mx:Button id='btn1' label='Button1' x='50' y='50' />");
              It is just an example that what i want to do...
              somehow can i do this?
              • 4. Re: Create controls through actionscript
                atta707 Level 2
                No you cannot. For lines like <mx:Button id='btn1' label='Button1' x='50' y='50' /> in MXML files the compiler doing all the dirty stuff to convert them to equivalent code like:

                btn1:Button =new Button();
                btn1.id="btn1";
                btn1.label="Button1";
                btn1.move(50,50);
                addchild(btn1);

                Unless you're willing to compile your MXML code into SWF on the fly addChild() thru the ActionScript code is the way to go. AFAIR, Adobe did had MXML compiler, as a Servlet Filter I think, but I can be wrong here. Google it and you might find it.