1 Reply Latest reply on Aug 28, 2013 9:24 PM by Flex harUI

    How to replace MXML element with another?

    andreitom

      Hi. I am pretty new to Flex but I find it very attractive.

       

      What I am trying to achieve is to have two different layouts and initialize them based on the user's choice. Each of these layouts is defined in its own mxml component.

       

      I have two components:

      <components:LeftAligned /> and <components:RightAligned />

       

      I could add both in the beginning and have only one visible but I don't want to go down that road. What I tried so far is to have an event handler that replaces the current instance but I hit a wall. Let's say that LeftAligned is the component initialized first and then I want to change it with RightAligned. Now:

      • If I try to replace the lement based on its id: newElement:RightAligned = new RightAligned(); LayoutArea = newElement; I get a implicit coercion error that it can't convert RightAligned to LeftAligned.
      • If I try to removeElement(LayoutArea); addElement(newElement); then I get an exception thrown from other parts of the application that call LayoutArea's methods (event based).

      What solutions are there for this? Thank you