3 Replies Latest reply on Mar 18, 2012 9:18 PM by Flex harUI

    add a UIComponent to a Sprite?

    JAXIMFLASH Level 1

      I'd like use the flex components as if they are regular display objects. I would like to add a TextInput instance to a sprite. During my debugguing, I see the spite but I do not see the TextInput instance.

      There are cases where I do not want to use MXML or the spark.components.Application and I just want to manipulate the components in pure AS3.

       

      How do I add the TextInput UIComponent instance to the sprite's display list?

       

      For example, here is a quick example of what I am trying to do:

       

      var sp:Sprite = new Sprite();

      var input:TextInput = new TextInput();

      input.width = 100;

      input.height = 50;

      input.text = "Hello World";

      sp.addChild(input);

        • 1. Re: add a UIComponent to a Sprite?
          Innovatology Level 3

          You can't do that easily. The Flex components communicate with eachother for many things such as measurement, layout, focus management etc. You would have to extend your Sprite to do all the stuff the framework normally does.

           

          You don't have to use MXML though. You can also write purely AS3 Flex projects. But the starting point will still be one of the Flex base classes.

          • 2. Re: add a UIComponent to a Sprite?
            JAXIMFLASH Level 1

            I could create my own elements using AS3, but it would be nice if I didn't have to and I could utilize some of the Flex components that are already prebuilt and are pretty great. (I would hope that this is made possible when the Flex Open Source movement gets into full swing.)

             

            Is there another way of doing this? Could I use some kind of general UIComponent instead of a Sprite and then add other UIComponents like TextInput to the main UIComponent? But then how do I add the main UIComponent to the stage?

            So the code would look something like:

             

            var main:UIComponent = new UIComponent();

            var input:TextInput = new TextInput();

            input.width = 100;

            input.height = 50;

            input.text = "Hello World";

            main.addChild(input);    //OR main.addElement(input);

             

            Basically I want to reduce the need to use MXML. (If I need to create one main MXML class, then that's probably fine.) I want to be able to use Flex components in pure AS3.Is there a strategy to do this?

            • 3. Re: add a UIComponent to a Sprite?
              Flex harUI Adobe Employee

              There is a lot of bootstrapping when the compiler generates code for MXML that is used by UIComponent. If you don’t use it, you will have to use a lot of glue.  Really small AS3 apps should not be using Flex components.

               

              If you want to use UIComponent and just want to avoid using MXML, the easiest way is to just have an empty MXML application and use the preinitialize event to start running all of your actionscript.

               

              You can also use –keep-generated-actionscript to see the AS generated by MXML and stitch it all back together.  It is a real pain though, and if you make certain kinds of changes you will need to re-stitch everything all over again.