2 Replies Latest reply on Jan 27, 2008 8:46 AM by cxf02

    Storing MXML Visuals in a variable

    vEr5e Level 1
      Everytime when I type in a MXML code, Flex is going to render them immediately onto the screen. If I want to store some MXML code in a variable and only show them on the screen when I want to, is this possible?

      Right now, I only know I could do that in Actionscript but it would be nice if I could do it directly in MXML instead of declaring the VBox, Buttons, etc in Actionscript to store in a variable.

        • 1. Re: Storing MXML Visuals in a variable
          wouter vdb
          You might want to use States. You can define different states in which you add/remove different components. You then switch states as needed.

          see: http://www.adobe.com/devnet/flex/quickstart/creating_states/
          • 2. Storing MXML Visuals in a variable
            cxf02 Level 1
            MXML code is compiled into action script from the compiler. The only way I could see this working would be if you stored MXML code in separate files or in the database. You would request them through a backend process that would compile them into a separate swf, then send them onto the client as another library.

            It sounds like you believe that MXML is compiled code. It's really like a 4GL representation of code, that produces bytecode at compile-time. Excecpt in the case of MXML, it ends up being transformed into AS, then compiled into ByteCode executed within the SWF plugin.

            You can create separate components from MXML and then create AS methods within them to instantiate other components into those containers. There are various design patterns that you could use to create colaboration between objects. However, without knowing more about what you are trying to accomplish, it sounds like you could look at "States" as the previous writer suggests, or the use of a ViewStack. Both can be powerful and work well with each other in showing and hiding Views.